fetchOrThrow
Wraps fetch so that a non-2xx response rejects with an HttpError, instead of
resolving like any other response — the throwing counterpart to safeFetch, for when a
failed request should fail loud. Network errors reject as fetch itself rejects them.
Available since v3.1.11
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input | RequestInfo | URL | URL or `Request` object passed to `fetch` |
init | RequestInit | Optional `RequestInit` options passed to `fetch` (optional) |
Returns
Section titled “Returns”Promise<Response> — The response, body unread, when its status is 2xx
Examples
Section titled “Examples”Fail loud on a non-2xx response
Section titled “Fail loud on a non-2xx response”Resolves with the response on success, rejects with an HttpError otherwise.
Handle a specific status
Section titled “Handle a specific status”HttpError carries the status, the URL and the response, so a caller can branch on it.
