Why is my TRY ... CATCH not working?
My CATCH is not catching the error, what am I doing wrong please?
HTML
JAVASCRIPT
9 Replies
what is the output?
I am getting a 404 error
surely my CATCH should handle this
being an error, shouldn't it ignore the "console.log(data)" ?
404 is a valid result for
fetch
, it isn't an exception
you requested a resource from the server, and the server responded that it couldn't find the resource
an exception would be if you can't reach the server, or DNS resolution fails, or the connection is reset mid-transferhow do i catch the 404 error
i want to be able to report "user not found"
you'll have to examine
res
, it will contain the HTTP status code of the responseahhhhh, gotcha, thank you
this worked
thank you 🙂
no problem 🙂 Glad to help!