DEV Community

[Comment from a deleted post]
 
mjoycemilburn profile image
MartinJ

Gosh - you're absolutely right. It's there in the Mozilla docs too - "the fetch() method ... returns a Promise that resolves to the Response to that request — as soon as the server responds with headers — even if the server response is an HTTP error status." In bold text too! It's funny how your eye can just skate over something like that when you're concentrating on something else.

Control ends up in the .catch with a JSON error, exactly as you said. But, hey, all isn't lost as it's easy enough to pick up response.status in the first .then() and redirect as in your try block.

As you say, it's all a matter of style but, to me, try/catch blocks always look a bit desperate!

I like your boiler-plate examples. I'll make a note of the abort template.

Regards, MJ