mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-19 09:34:02 +00:00
16 lines
424 B
TypeScript
16 lines
424 B
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)
|
|
}
|
|
})
|
|
}
|