Skip to content

Commit 5c5bd73

Browse files
author
woodcutter
committed
fix(ApiCall): fix AbortSignal support
1 parent 43d4d97 commit 5c5bd73

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unity-api",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "REST-API helper, wrapped around fetch.",
55
"main": "dist/index.js",
66
"scripts": {

src/call.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ function call(
3535

3636
const fetchPromise = fetch(url, accumulatedFetchOptions)
3737
.then(response => {
38+
// Fetch AbortSignal support
39+
// Note: When abort() is called, the fetch() promise rejects with an AbortError
40+
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
41+
// https://developer.mozilla.org/en-US/docs/Web/API/AbortController
42+
if (signal.aborted) {
43+
const abortError = new Error('Fetch abort signal');
44+
abortError.name = 'AbortError';
45+
46+
throw abortError;
47+
}
48+
3849
// Promise.prototype.finally is proposal
3950
// https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally
4051
APIAbort.destroy(uuid);

0 commit comments

Comments
 (0)