Skip to content

Commit 8bef30d

Browse files
committed
[fix] abort controller issue
1 parent 707007d commit 8bef30d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

packages/sdk-middleware-http/src/http.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,15 @@ export default function createHttpMiddleware({
6868
} = {},
6969
fetch: fetcher,
7070
abortController: _abortController,
71+
getAbortController
7172
}: HttpMiddlewareOptions): Middleware {
7273
if (!fetcher && typeof fetch === 'undefined')
7374
throw new Error(
7475
'`fetch` is not available. Please pass in `fetch` as an option or have it globally available.'
7576
)
76-
if (timeout && !_abortController && typeof AbortController === 'undefined')
77+
if (timeout && !getAbortController && !_abortController && typeof AbortController === 'undefined')
7778
throw new Error(
78-
'`AbortController` is not available. Please pass in `AbortController` as an option or have it globally available when using timeout.'
79+
'`AbortController` is not available. Please pass in `getAbortController` as an option or have AbortController globally available when using timeout.'
7980
)
8081
let fetchFunction: typeof fetch
8182
if (fetcher) {
@@ -87,15 +88,15 @@ export default function createHttpMiddleware({
8788
fetchFunction = fetch
8889
}
8990

90-
let abortController
91-
if (timeout || _abortController)
92-
// eslint-disable-next-line
93-
abortController = _abortController || new AbortController()
94-
9591
return (next: Next): Next => (
9692
request: MiddlewareRequest,
9793
response: MiddlewareResponse
9894
) => {
95+
let abortController
96+
if (timeout || getAbortController || _abortController)
97+
// eslint-disable-next-line
98+
abortController = getAbortController() || _abortController || new AbortController()
99+
99100
const url = host.replace(/\/$/, '') + request.uri
100101
const body =
101102
typeof request.body === 'string' || Buffer.isBuffer(request.body)

types/sdk.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ export type HttpMiddlewareOptions = {
243243
maxDelay?: number,
244244
},
245245
fetch?: typeof fetch,
246-
abortController?: AbortController,
246+
abortController?: AbortController, // deprecated
247+
getAbortController: () => AbortController
247248
}
248249
export type QueueMiddlewareOptions = {
249250
concurrency: number,

0 commit comments

Comments
 (0)