I'm modifying a script that makes request to URLs stored inside CSV file. Some of the links are broken or they no longer exists. I need to filter out those links so that node would continue on with good links and would not crash. How should I handle this error so that node wouldn't crash? This is a snippet of my code
var req = ref.protocol.get(options, function(res) {
res.on('data', function(data) {
f.write(data);
}).on('end', function() {
f.end();
});
});
req.on('response', function(err) {
if(err.statusCode == '404') {
console.log("Response ", err);
}
});
req.on('error', function(err) {
console.log("This is error ----" + err);
});
req.end();
Edit : After fiddling around with the code, I found that Node crashes only on 302 status. It does not seem to have problem with 404.