Skip to content

Commit f8af58f

Browse files
authored
@uppy/utils: add cause support for AbortErrors (#4198)
Refs: whatwg/webidl#1179
1 parent cc4c52a commit f8af58f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import hasOwnProperty from './hasProperty.js'
12
/**
23
* Little AbortController proxy module so we can swap out the implementation easily later.
34
*/
45
export const { AbortController } = globalThis
56
export const { AbortSignal } = globalThis
6-
export const createAbortError = (message = 'Aborted') => new DOMException(message, 'AbortError')
7+
export const createAbortError = (message = 'Aborted', options) => {
8+
const err = new DOMException(message, 'AbortError')
9+
if (options != null && hasOwnProperty(options, 'cause')) {
10+
Object.defineProperty(err, 'cause', { __proto__: null, configurable: true, writable: true, value: options.cause })
11+
}
12+
return err
13+
}

packages/@uppy/utils/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ declare module '@uppy/utils/lib/toArray' {
241241
declare module '@uppy/utils/lib/AbortController' {
242242
export const AbortController: typeof globalThis.AbortController
243243
export const AbortSignal: typeof globalThis.AbortSignal
244-
export function createAbortError(message?: string): DOMException
244+
export function createAbortError(message?: string, options?: ErrorOptions): DOMException
245245
}
246246

247247
declare module '@uppy/utils/lib/getDroppedFiles' {

0 commit comments

Comments
 (0)