npm / minipass-fetch

An implementation of window.fetch in Node.js using Minipass streams
Other
54 stars 11 forks source link

Expose AbortError #50

Closed timdp closed 2 years ago

timdp commented 2 years ago

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:

nlf commented 2 years ago

we expose FetchError already so following that precedent for AbortError totally makes sense to me. thanks for the contribution!