Because window.fetch isn't designed to be transparent about the cause of request errors, we have to come up with our own solutions.
The basics:
- A cancelled request is rejected with an
AbortError. You can check if the reason for rejection was that the request was aborted by checking theError'snameisAbortError.
fetch(url, { signal }).catch(err => {
if (err.name === 'AbortError') {
// request was aborted
}
})-
All operational errors other than aborted requests are rejected with a FetchError. You can handle them all through the promise
catchclause. -
All errors come with an
err.messagedetailing the cause of errors. -
All errors originating from
node-fetchare marked with a customerr.type. -
All errors originating from Node.js core are marked with
err.type = 'system', and in addition contain anerr.codeand anerr.errnofor error handling. These are aliases for error codes thrown by Node.js core. -
Programmer errors are either thrown as soon as possible, or rejected with default
Errorwitherr.messagefor ease of troubleshooting.
List of error types:
- Because we maintain 100% coverage, see test.js for a full list of custom
FetchErrortypes, as well as some of the common errors from Node.js