Skip to content

Commit 61b3b5a

Browse files
SoftwareAndOutsourcingLinusU
andauthoredMar 1, 2022
fix: cancel request example import (#1513)
* Fix example * Fix formatting Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
1 parent 5e78af3 commit 61b3b5a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ You may cancel requests with `AbortController`. A suggested implementation is [`
470470
An example of timing out a request after 150ms could be achieved as the following:
471471

472472
```js
473-
import fetch from 'node-fetch';
473+
import fetch, { AbortError } from 'node-fetch';
474474

475475
// AbortController was added in node v14.17.0 globally
476476
const AbortController = globalThis.AbortController || await import('abort-controller')
@@ -484,7 +484,7 @@ try {
484484
const response = await fetch('https://example.com', {signal: controller.signal});
485485
const data = await response.json();
486486
} catch (error) {
487-
if (error instanceof fetch.AbortError) {
487+
if (error instanceof AbortError) {
488488
console.log('request was aborted');
489489
}
490490
} finally {
@@ -868,4 +868,4 @@ Thanks to [github/fetch](https://github.com/github/fetch) for providing a solid
868868
[error-handling.md]: https://github.com/node-fetch/node-fetch/blob/master/docs/ERROR-HANDLING.md
869869
[FormData]: https://developer.mozilla.org/en-US/docs/Web/API/FormData
870870
[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

0 commit comments

Comments
 (0)
Please sign in to comment.