Skip to content

Commit 78010a6

Browse files
committed
use a normal Error when DOMException isn't available
1 parent 36d64d0 commit 78010a6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/toolkit/src/query/utils/signals.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
// AbortSignal.timeout() is currently baseline 2024
22
export const timeoutSignal = (milliseconds: number) => {
33
const abortController = new AbortController()
4-
setTimeout(
5-
() => abortController.abort(new DOMException('', 'TimeoutError')),
6-
milliseconds,
7-
)
4+
setTimeout(() => {
5+
const message = 'signal timed out'
6+
const name = 'TimeoutError'
7+
abortController.abort(
8+
// some environments (React Native, Node) don't have DOMException
9+
typeof DOMException !== 'undefined'
10+
? new DOMException(message, name)
11+
: Object.assign(new Error(message), { name }),
12+
)
13+
}, milliseconds)
814
return abortController.signal
915
}
1016

0 commit comments

Comments
 (0)