I have a bit of code that loops through a list of URLs and fetches them using needle, I am having a problem as it seems if one of the URLs is malformed needle throws a URIError that stops the execution.
What I want is for the bad URL to be marked but the loop continues, I have the following code that include a try-catch block but it still throws an error
URIError: URI malformed
at decodeURIComponent (native)
at parseSetCookieString (node_modules/needle/lib/cookies.js:44:35)
at node_modules/needle/lib/cookies.js:54:18
at Array.reduce (native)
at Object.parseSetCookieHeader [as read] (node_modules/needle/lib/cookies.js:53:17)
at ClientRequest.<anonymous> (node_modules/needle/lib/needle.js:418:30)
at ClientRequest.g (events.js:199:16)
at ClientRequest.emit (events.js:107:17)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:426:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:111:23)
The loop looks like this
for (var i =0; i < items.length; i++)
{
var url = items[i].link;
var options = {};
(function(inner_url){
try {
needle.get(inner_url, options, function(err, res) {
if(err) {
console.log(err)
} else {
console.log('success')
}
})
} catch (URIError) {
console.log(URIError)
}
})(url)
}
Any pointers?
Thanks