Re: [whatwg/fetch] Consider response.throwIfNotOk() (Issue #1679)

I think it's kind of common to see ppl doing something in the lines of:

```js
async function get() {
  const res = await fetch(request)
  if (!res.ok) throw new Error('not okey status code.')
  return res.json()
}
```
but this will leave the request hanging and still consume bandwidth until it downloads everything?
And lower the max concurrent request being made at one single point?

if they would have done it more correctly then it would have been something like:
```js
async function get() {
  const ctrl = new AbortController()
  const res = await fetch(url, { signal: ctrl.siganl })
  if (!res.ok) ctrl.abort(new Error('not okey status code.'))
  return res.json()
}
```
This would abort the request faster if it was not a okey response.

So maybe an assert option would be useful by helping the developer doing the "correct" thing by aborting the request prematurely if the response is not okey? if by that means doing the most sensable "correct" thing. 

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1679#issuecomment-1789408412
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/issues/1679/1789408412@github.com>

Received on Wednesday, 1 November 2023 18:00:29 UTC