- From: Jake Archibald <notifications@github.com>
- Date: Wed, 28 Jun 2023 01:29:52 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Wednesday, 28 June 2023 08:29:58 UTC
@domenic
> The only case in which this method would be a win is if you're treating network errors (no response) and not-OK errors uniformly
Totally agree. I tend to write something like this:
```js
async function getData(url) {
const response = await fetch(url);
try {
const data = await response.json();
// Use presumably more accurate error data from the response:
if (data.error) throw Error(data.error);
return data;
} catch (error) {
// Error seems like a JSON parsing issue:
if (response.ok) throw error;
// Construct an error from the status:
throw Error(`Response error: ${response.status} - ${response.statusText}`);
}
}
```
`throwIfNotOk` doesn't really help here.
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1679#issuecomment-1610991197
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/fetch/issues/1679/1610991197@github.com>
Received on Wednesday, 28 June 2023 08:29:58 UTC