Skip to content

Commit

Permalink
@uppy/utils: add cause support for AbortErrors (#4198)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Nov 7, 2022
1 parent cc4c52a commit f8af58f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/@uppy/utils/src/AbortController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import hasOwnProperty from './hasProperty.js'
/**
* Little AbortController proxy module so we can swap out the implementation easily later.
*/
export const { AbortController } = globalThis
export const { AbortSignal } = globalThis
export const createAbortError = (message = 'Aborted') => new DOMException(message, 'AbortError')
export const createAbortError = (message = 'Aborted', options) => {
const err = new DOMException(message, 'AbortError')
if (options != null && hasOwnProperty(options, 'cause')) {
Object.defineProperty(err, 'cause', { __proto__: null, configurable: true, writable: true, value: options.cause })
}
return err
}
2 changes: 1 addition & 1 deletion packages/@uppy/utils/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ declare module '@uppy/utils/lib/toArray' {
declare module '@uppy/utils/lib/AbortController' {
export const AbortController: typeof globalThis.AbortController
export const AbortSignal: typeof globalThis.AbortSignal
export function createAbortError(message?: string): DOMException
export function createAbortError(message?: string, options?: ErrorOptions): DOMException
}

declare module '@uppy/utils/lib/getDroppedFiles' {
Expand Down

0 comments on commit f8af58f

Please sign in to comment.