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

Add isAbortError #33

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.1.2 (unreleased)
=====

* (improvement) Add `isAbortError()`.


2.1.1
=====

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Development
### Releases

1. Check the CHANGELOG, to ensure that the next version number is correct according to semver and there is no "(unreleased)" after the next version number.
2. Commit these changes, commit message "Release x.y.z"
3. Push these changes
4. Tag the latest commit with "x.y.z"
5. Push the tag.
2. If necessary, commit these changes, commit message "Release x.y.z".
3. Tag the latest commit with "x.y.z".
4. Push commit + tag.
5. Create a release in GitHub.

Publishing to npm is done automatically in a GitHub action.
15 changes: 15 additions & 0 deletions src/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Returns whether the given error is an abort "error".
*
* This will be thrown in a fetch() when aborting the request.
*
* @example
* const controller = new AbortController();
* fetch(..., {signal: controller.signal})
* .catch(error => isAbortError(error) // will be true)
* controller.abort();
*/
export function isAbortError (error: unknown) : boolean
{
return error instanceof DOMException && error.name === "AbortError";
}