DEV Community

[Comment from a deleted post]
Collapse
 
forestdev profile image
Dominykas Bartkus • Edited

You should also remember that fetch does not consider anything bellow 500 from the response to be an error.

Thus if you're retrying the request because of a timeout, you should specifically check for the status code 408.

All other codes should also probably be handled accordingly. At least there's always been a need to handle specific error codes for me rather than checking

    switch (true) {
        case response.ok: {
            // That's really cool.
            // But I should really also check the status code as well
        }

        default: {
            // Whatever then
        }
    }
Collapse
 
ycmjason profile image
YCM Jason • Edited

Yup. Thank you for pointing out that!

In my case, I only want to handle network failure. So I haven't mentioned it.