@uppy/utils
Version:
Shared utility functions for Uppy Core and plugins maintained by the Uppy team.
17 lines (15 loc) • 424 B
text/typescript
import NetworkError from './NetworkError.js'
/**
* Wrapper around window.fetch that throws a NetworkError when appropriate
*/
export default function fetchWithNetworkError(
...options: Parameters<typeof globalThis.fetch>
): ReturnType<typeof globalThis.fetch> {
return fetch(...options).catch((err) => {
if (err.name === 'AbortError') {
throw err
} else {
throw new NetworkError(err)
}
})
}