DOMException.ts
This file
Path
source/errors/DOMException.ts
20 lines · 1017 bytes · TypeScript
Last changed by
Fix the name of the error when aborting a request (#482)Cristobal Dabedbefore adoptionce8588d
History of this fileTake it
Fix the name of the error when aborting a request (#482)Cristobal Dabedbefore adoptionce8588d
lines 1–3why, one step back1// DOMException is supported on most modern browsers and Node.js 18+.2// @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException#browser_compatibility3const isDomExceptionSupported = Boolean(globalThis.DOMException);Fix abortions between retries (#433)Richie Bendallbefore adoptiondddf7ba
line 4why, one step back4Fix the name of the error when aborting a request (#482)Cristobal Dabedbefore adoptionce8588d
line 5why, one step back5// TODO: When targeting Node.js 18, use `signal.throwIfAborted()` (https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted)Fix abortions between retries (#433)Richie Bendallbefore adoptiondddf7ba
line 6why, one step back6export function composeAbortError(signal?: AbortSignal) {Fix the name of the error when aborting a request (#482)Cristobal Dabedbefore adoptionce8588d
lines 7–19why, one step back7 /*8 NOTE: Use DomException with AbortError name as specified in MDN docs (https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort)9 > When abort() is called, the fetch() promise rejects with an Error of type DOMException, with name AbortError.10 */11 if (isDomExceptionSupported) {12 return new DOMException(signal?.reason ?? 'The operation was aborted.', 'AbortError');13 }1415 // DOMException not supported. Fall back to use of error and override name.16 const error = new Error(signal?.reason ?? 'The operation was aborted.');17 error.name = 'AbortError';1819 return error;Fix abortions between retries (#433)Richie Bendallbefore adoptiondddf7ba
line 20why, one step back20}