- From: Justin Fagnani <notifications@github.com>
- Date: Tue, 27 Jun 2023 21:14:40 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Wednesday, 28 June 2023 04:14:45 UTC
@domenic I think it is relatively common that you want to treat not-OK errors as exceptions. This is quite often the rationale for people still using libraries axios over fetch, and I've unfortunately seen a lot of code like: ```ts let data = await (await fetch(url)).text(); ``` It's also why some libraries like React Query specially call out `fetch()` as needing the author to throw errors: https://tanstack.com/query/v4/docs/react/guides/query-functions#usage-with-fetch-and-other-clients-that-do-not-throw-by-default We have this in Lit Task too, where we differentiate successful task runs from errored run, and to make a task from fetch you usually need to make it throw to designate 4xx, 5xx, etc. error. I think one of the big benefits from a more ergonomic API is in education. If throwing on no-OK responses is a single option or one-liner, more examples will include it, and more developers reading those examples will learn that errors need handling whether they use the assertion method or branch on status. -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/1679#issuecomment-1610671345 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/fetch/issues/1679/1610671345@github.com>
Received on Wednesday, 28 June 2023 04:14:45 UTC