AbortController and fetch: how to distinguish network error from abort error

Viewed 2412

So I have a fetch with an abort controller like so:

async function fn() {
  const abortController = new AbortController();

  try {
    const response = await fetch(/* ... */, { signal: abortController.signal });
    // ...
  } catch (e) {
    // how can I tell if `e` is from a network error (e.g. offline)
    // or an error from an abort
  }
}

How can I tell if e is a network error or an abort error?

1 Answers
Related