Does Fetch API throw errors when a request fails?
Hey folks, been wrestling with fetch() lately and gotta ask—does Fetch API throw errors when a request fails? Like, I *thought* it did, but then my app just silently ate a 404 like it was nothing.
From what I’ve seen, fetch only rejects the promise on network errors (no connection, DNS fail, etc.). But HTTP errors (404, 500)? Nah, those still *resolve*—you gotta check `response.ok` or the status code yourself.
Kinda weird, right? Feels like it should throw for *any* failed request.
How do y’all handle this? Manually checking status codes every time? Or wrap it in some helper function?
Also, am I missing something? Does fetch API throw in some cases I don’t know about?
(Also, sorry for typos, typing this on my phone lol)
Hey folks, been wrestling with fetch() lately and gotta ask—does Fetch API throw errors when a request fails? Like, I *thought* it did, but then my app just silently ate a 404 like it was nothing.
From what I’ve seen, fetch only rejects the promise on network errors (no connection, DNS fail, etc.). But HTTP errors (404, 500)? Nah, those still *resolve*—you gotta check `response.ok` or the status code yourself.
Kinda weird, right? Feels like it should throw for *any* failed request.
How do y’all handle this? Manually checking status codes every time? Or wrap it in some helper function?
Also, am I missing something? Does fetch API throw in some cases I don’t know about?
(Also, sorry for typos, typing this on my phone lol)
