Skip to content

Commit

Permalink
fix: cancel request example import (#1513)
Browse files Browse the repository at this point in the history
* Fix example

* Fix formatting

Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>

Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
  • Loading branch information
SoftwareAndOutsourcing and LinusU committed Mar 1, 2022
1 parent 5e78af3 commit 61b3b5a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -470,7 +470,7 @@ You may cancel requests with `AbortController`. A suggested implementation is [`
An example of timing out a request after 150ms could be achieved as the following:

```js
import fetch from 'node-fetch';
import fetch, { AbortError } from 'node-fetch';

// AbortController was added in node v14.17.0 globally
const AbortController = globalThis.AbortController || await import('abort-controller')
Expand All @@ -484,7 +484,7 @@ try {
const response = await fetch('https://example.com', {signal: controller.signal});
const data = await response.json();
} catch (error) {
if (error instanceof fetch.AbortError) {
if (error instanceof AbortError) {
console.log('request was aborted');
}
} finally {
Expand Down Expand Up @@ -868,4 +868,4 @@ Thanks to [github/fetch](https://github.com/github/fetch) for providing a solid
[error-handling.md]: https://github.com/node-fetch/node-fetch/blob/master/docs/ERROR-HANDLING.md
[FormData]: https://developer.mozilla.org/en-US/docs/Web/API/FormData
[Blob]: https://developer.mozilla.org/en-US/docs/Web/API/Blob
[File]: https://developer.mozilla.org/en-US/docs/Web/API/File
[File]: https://developer.mozilla.org/en-US/docs/Web/API/File

0 comments on commit 61b3b5a

Please sign in to comment.