As part of my Gulp build process, I'm fetching an external RSS feed, converting it into JSON, and writing it into a file. Sometimes the RSS feed is unavailable, which causes the build process to return an error:
Error: socket hang up at connResetException (internal/errors.js:607:14)
at TLSSocket.socketOnEnd (_http_client.js:493:23)
at TLSSocket.emit (events.js:327:22)
at TLSSocket.EventEmitter.emit (domain.js:529:15)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
The task is run as part of a gulp.parallel
operation. It isn't essential to the rest of the process, and I'd like the build to continue even if this one task fails.
I've tried to implement error handling as follows:
// RSS to JSON
const { parse } = require('rss-to-json');
const fs = require('fs');
function parseRss(cb) {
try {
return parse('https://feeds.buzzsprout.com/1794525.rss')
.then(rss => {
fs.writeFileSync('./site/_data/podcast.json', JSON.stringify(rss, null, 3));
});
} catch(e) {
console.log(e);
}
}
But it appears to do nothing at all. How would I go about modifying the task above to make sure an error won't stop the entire operation?