Skip to content

Commit

Permalink
fix(ApiCall): fix AbortSignal support
Browse files Browse the repository at this point in the history
  • Loading branch information
woodcutter committed Oct 25, 2018
1 parent 43d4d97 commit 5c5bd73
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unity-api",
"version": "3.0.0",
"version": "3.0.1",
"description": "REST-API helper, wrapped around fetch.",
"main": "dist/index.js",
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions src/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ function call(

const fetchPromise = fetch(url, accumulatedFetchOptions)
.then(response => {
// Fetch AbortSignal support
// Note: When abort() is called, the fetch() promise rejects with an AbortError
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
// https://developer.mozilla.org/en-US/docs/Web/API/AbortController
if (signal.aborted) {
const abortError = new Error('Fetch abort signal');
abortError.name = 'AbortError';

throw abortError;
}

// Promise.prototype.finally is proposal
// https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally
APIAbort.destroy(uuid);
Expand Down

0 comments on commit 5c5bd73

Please sign in to comment.