QwisoDev:
The need of try/catch in a live script such as yours cannot be avoided. This is a great scenario for what it was made to do. There’s no need to shift to another library if you’ve already got the code written how you like
try {
// try to get or post to the api here
// as long as twitch returns a response, null or otherwise
// then the attempt was successful and code continues executing
// note: it skips the error block of code
} catch(error) {
// if the get or post failed due to connection errror, timeout, etc ..
// this area of code will fire
// the variable `error` will contain any useable data about the error
// also, despite the error, the script will continue executing further
}
I gave this a try and put my entire API check inside the try statement, but it doesn’t appear to work… Now all I’m getting is this error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND. Hostname: https://tmi.twitch.tv
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
I figured out which API was giving the problem, which is the chatter’s list. I’ve disabled it for now because it’s on Twitch’s end, but I’m still confused as to why the try/catch didn’t catch the error and prevent the crashes