-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from 21TORR/abort-error
Add `isAbortError`
- Loading branch information
Showing
3 changed files
with
25 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
2.1.2 (unreleased) | ||
===== | ||
|
||
* (improvement) Add `isAbortError()`. | ||
|
||
|
||
2.1.1 | ||
===== | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |