Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 61b3b5a

Browse filesBrowse files
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
Copy full SHA for 61b3b5a

File tree

Expand file treeCollapse file tree

1 file changed

+3
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+3
-3
lines changed
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+3-3Lines changed: 3 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.