mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-23 18:29:09 +00:00
Co-authored-by: Mikael Finstad <finstaden@gmail.com> Co-authored-by: Nick Rutten <2504906+nickrttn@users.noreply.github.com> Co-authored-by: Murderlon <merlijn@soverin.net> Co-authored-by: Artur Paikin <artur@arturpaikin.com>
16 lines
424 B
TypeScript
16 lines
424 B
TypeScript
import NetworkError from './NetworkError.ts'
|
|
|
|
/**
|
|
* 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)
|
|
}
|
|
})
|
|
}
|