Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cancel request example import #1513

Merged
merged 2 commits into from Mar 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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