I have the below code:
var request = require('request');
var rp = require('request-promise');
module.exports = async function(context, req) {
var arr = [[url1],[url2]]
for (i = 0; i < arr.length; i++) {
func(context, arr[i]);
}
}
function func(context, urls) {
const promises = urls.map(item => {
return rp({
uri: item,
simple: false,
resolveWithFullResponse: true
}).then(response => {
if (response.statusCode == 403) {
var msg = "hello";
return msg;
} else {
return null;
}
});
});
return Promise.all(promises).then(data => {
// remove null results from array
return data.filter(item => item !== null);
});
}
And I keep getting this error. Sometimes it works, sometimes it doesn't. How can I fix this, and why does it work sometimes and sometimes not.
Result: Failure
Exception: RequestError: Error: connect ETIMEDOUT
Do I need to inclue a pool
option? Or perhaps a timeout
? The error seems to be due to the size of arr
.