Try Catch
Answered
(-.-) posted this in #help-forum
Original message was deleted.
Answered by Pearls
It is not necessary, but it is recommended to add some sort of error control. either using a catch statement after the fetch (fetch().catch) or just a full on try/catch.
10 Replies
It is not necessary, but it is recommended to add some sort of error control. either using a catch statement after the fetch (fetch().catch) or just a full on try/catch.
Answer
When I use try catch it doesn't catch 400 errors, should I throw an exception manually?
I want to be able to activate error.js in catch and also send this error to a log service
this code would appear to be correct, let me explain it a little for your own understanding.
The !res.ok checks if the response status code is not a success status code (200-299), if it isnt it will throw an exception. The thing with this is that it doesnt check for network errors or parsing errors, thats where your try/catch statement comes in and catches those errors and logs them to console.
The !res.ok checks if the response status code is not a success status code (200-299), if it isnt it will throw an exception. The thing with this is that it doesnt check for network errors or parsing errors, thats where your try/catch statement comes in and catches those errors and logs them to console.
I understand, so within the catch block I could send this error to a log service?
In other words, I don't need to return errors within catch? Can I just return them in the console?
Yes thats correct
Thanks a lot for the help.
Masai Lion
Hi