File tree 1 file changed +3
-3
lines changed
1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -470,7 +470,7 @@ You may cancel requests with `AbortController`. A suggested implementation is [`
470
470
An example of timing out a request after 150ms could be achieved as the following:
471
471
472
472
``` js
473
- import fetch from ' node-fetch' ;
473
+ import fetch , { AbortError } from ' node-fetch' ;
474
474
475
475
// AbortController was added in node v14.17.0 globally
476
476
const AbortController = globalThis .AbortController || await import (' abort-controller' )
@@ -484,7 +484,7 @@ try {
484
484
const response = await fetch (' https://example.com' , {signal: controller .signal });
485
485
const data = await response .json ();
486
486
} catch (error) {
487
- if (error instanceof fetch . AbortError ) {
487
+ if (error instanceof AbortError) {
488
488
console .log (' request was aborted' );
489
489
}
490
490
} finally {
@@ -868,4 +868,4 @@ Thanks to [github/fetch](https://github.com/github/fetch) for providing a solid
868
868
[error-handling.md]: https://github.com/node-fetch/node-fetch/blob/master/docs/ERROR-HANDLING.md
869
869
[FormData]: https://developer.mozilla.org/en-US/docs/Web/API/FormData
870
870
[Blob]: https://developer.mozilla.org/en-US/docs/Web/API/Blob
871
- [File]: https://developer.mozilla.org/en-US/docs/Web/API/File
871
+ [File]: https://developer.mozilla.org/en-US/docs/Web/API/File
You can’t perform that action at this time.
0 commit comments