Does Fetch API throw errors when a request fails? Alternatively: How does Fetch API throw errors, and

18 Replies, 885 Views

Kinda wild that fetch doesn’t throw for HTTP errors, right? Like, a 404 *is* a failure, so why not reject?

I ended up writing a tiny utility that wraps fetch and auto-throws for non-2xx responses. Also adds timeouts, which fetch doesn’t do natively.

If you don’t wanna DIY, check out `wretch`—it’s a fetch wrapper with better error handling.

Messages In This Thread



Users browsing this thread: 1 Guest(s)