#Try Catch

11 messages · Page 1 of 1 (latest)

meager hearthBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

gusty jolt
#

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.

wintry pagoda
#

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

gusty jolt
# wintry pagoda

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.

wintry pagoda
#

In other words, I don't need to return errors within catch? Can I just return them in the console?

gusty jolt
#

Yes thats correct

wintry pagoda
#

Thanks a lot for the help.

next nymph
#

Hi