DEV Community

Discussion on: Error Handling With Fetch

savagepixie profile image

A question worth asking is if a response other than 2xx or 3xx should be treated as an error. I'm not saying it shouldn't, but I don't think that should be the default either. Depending on what the call might return, you could have different handlers for what to do depending on the data you receive (array of objects vs empty response, for instance), and leave the catch to handle only network errors.

Again, I'm not saying this is the way to go, just saying that a 400 isn't always worth throwing an error.