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){caseresponse.ok:{// That's really cool.// But I should really also check the status code as well}default:{// Whatever then}}
Hey! I'm YCMJason, a Software Engineer in London 👨💻. Love diving into tech puzzles and sharing them! 🧩
All views expressed here are my own opinions, so please take them with a pinch of salt! 🧂
You should also remember that
fetch
does not consider anything bellow500
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
Yup. Thank you for pointing out that!
In my case, I only want to handle network failure. So I haven't mentioned it.