fetch() settles when it has a response, not when the request succeeded. A 404 or a 500 is a complete HTTP response: the server answered. So the promise fulfills with a Response, and success is yours to check: response.ok is true only for an ok status, 200 to 299, and response.status holds the code.
The promise rejects only when there is no response to hand over:
- Network error →
TypeError. DNS failure, a refused or reset connection, a failed CORS check, a request blocked by CSP, mixed content or a bad port, andredirect: 'error'meeting a redirect. The Fetch Standard turns each into one network error (type"error", status 0) and rejects with aTypeError, so the page can't tell them apart; the details show only in the DevTools console. The message is browser-specific: Chrome printsFailed to fetch, FirefoxNetworkError when attempting to fetch resource. - Invalid input →
TypeError, thrown while building theRequest: an unparsable URL, or a body on aGET. - Abort → the signal's reason: a
DOMExceptionnamedAbortErrorforcontroller.abort(),TimeoutErrorforAbortSignal.timeout().
The promise fulfills once the status and headers arrive; the body streams in afterwards. So errors can also surface later, when you read the body. A connection that drops mid-body makes response.text() reject with a TypeError. .json() rejects with a SyntaxError when the body isn't JSON, such as an HTML error page or an empty body.
A body can be read once. Any reading method sets bodyUsed to true, and a second .json() rejects with a TypeError. To read it twice, call response.clone() before the first read.
The usual wrapper awaits fetch(), throws its own error when !response.ok, with the status and the error body, and only then parses.