You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need that abortable async node api to reject with AbortError.
On the browser AbortError is instanceofDOMException,
We don't have DOMException in node, so we need to make it instanceofError
abortError = new Error(), abortError.name = "AbortError";
We need to document that
unfortunately browser code that uses error instanceof DOMException && error.name === "AbortError" will not detect it
On the browser, when async flow is aborted using AbortController, the flow is expected to return rejected promise, with an AbortError ().
Spec words: "APIs that rely upon AbortController are encouraged to respond to abort() by rejecting any unsettled promise with a new "AbortError" DOMException." spec link.
Motivation: Without rejecting and using well-known value, you might end up with never resolving promises up the chain, or with unexpected errors.
currently The only built-in api that supports AbortContoller is fetch, example:
const c = new AbortController();
const p = fetch('', { signal: c.signal });
c.abort();
try {
await p;
} catch (e) {
if (e instanceof DOMException && e.name === "AbortError") {
// aborted by us, no need to do anything
} else {
// real error
console.error(e)
}
}
On the browser AbortError is not a special constructor, but an instance of DOMException:
new DOMException('Aborted', 'AbortError'), with name=AbortError and a custom message
The text was updated successfully, but these errors were encountered:
Per #33528
TL;DR;
instanceof
DOMException
,DOMException
in node, so we need to make itinstanceof
Error
abortError = new Error(), abortError.name = "AbortError";
error instanceof DOMException && error.name === "AbortError"
will not detect itOn the browser, when async flow is aborted using AbortController, the flow is expected to return rejected promise, with an
AbortError
().Spec words: "APIs that rely upon AbortController are encouraged to respond to abort() by rejecting any unsettled promise with a new "AbortError" DOMException." spec link.
Motivation: Without rejecting and using well-known value, you might end up with never resolving promises up the chain, or with unexpected errors.
currently The only built-in api that supports
AbortContoller
is fetch, example:On the browser AbortError is not a special constructor, but an instance of
DOMException
:new DOMException('Aborted', 'AbortError'), with
name=AbortError
and a custom messageThe text was updated successfully, but these errors were encountered: