What is the best way to catch the error thrown from inside the setInterval
? Currently from the code below, on throwing the exception, the control does not reach catch
.
try {
timer = setInterval(() => {
if (moment().diff(lastProcessTime, 'minute') >= 2) {
// Taking too long!
clearInterval(timer);
throw new Error({ code: -1, message: `Taking too long to response:: ${urls[0]}` });
}
}, 1000);
await c.downloadAndSaveDataFromRssUrls(configs, urls);
clearInterval(timer);
return Promise.resolve();
} catch (err) {
clearInterval(timer);
console.log(err);
return Promise.resolve();
}