Currently, if I pass in an AbortSignal and want to detect why the promise rejected, I have to write:
import fetch from 'minipass-fetch'
import AbortError from 'minipass-fetch/lib/abort-error'
... in order to use the type:
try {
await fetch('https://example.com', { signal: AbortSignal.timeout(1000) })
} catch (err) {
if (err instanceof AbortError) {
// Timed out
} else {
// Something else went wrong
}
}
This PR turns the preamble into:
import fetch, { AbortError } from 'minipass-fetch'
... which is in line with how we're already exporting FetchError.
Playing devil's advocate:
I could also check err.name, err.code, or err.type, but none of those are guaranteed to originate from minipass-fetch. I'm not a fan of duck typing when it comes to errors.
Other runtimes don't support this scenario either:
Node 17.7.2 (with --experimental-fetch) generates a vanilla Error with code = 'ABORT_ERR'.
Chrome generates a DOMException.
I didn't check Firefox, Safari, Deno, or Cloudflare Workers.
Currently, if I pass in an
AbortSignal
and want to detect why the promise rejected, I have to write:... in order to use the type:
This PR turns the preamble into:
... which is in line with how we're already exporting
FetchError
.Playing devil's advocate:
err.name
,err.code
, orerr.type
, but none of those are guaranteed to originate from minipass-fetch. I'm not a fan of duck typing when it comes to errors.--experimental-fetch
) generates a vanillaError
withcode = 'ABORT_ERR'
.DOMException
.