Next.js fetch() not throwing error on failed request?
A little confused with this one. I'm making requests with the fetch api but when the response returns an error (400) it doesn't acknowledge that and it's not caught.
is there something I'm doing wrong?
1 Reply
fetch does not throw on HTTP errors, it only throws on network errors
you need to check
res.ok
which will be false if the HTTP code of the response isn't in the 2xx range
so
that is because a response of HTTP 400 You Done Goofed is not a failed request, it's a successful request that returned a HTTP error status