'Error 'event handler' not 'handling' ECONNRESET
I am using the library request to post data but I constantly get the error ECONNRESET even though I have an error event handler for it. Sometimes my code does indeed handle the error, but not everytime.
I have this in a loop:
request.post(url, {form:{data}}).on('error',
function(err){
if(err === 'ECONNRESET'){
console.log('ECONNRESET')
}
})
And, as described, I still get this error:
throw er; // Unhandled 'error' event
^ Error: read ECONNRESET
Solution 1:[1]
Seems like .on('error', ...); can't catch ECONNRESET after N times so the only way to solve if (afaik now) is using process.on('uncaughtException', function(error) {})
I hope this help other people :)
Solution 2:[2]
Wrap all the code you have using request in a try {} clause, followed by
catch (error) {
console.error (error)
}
From something you wrote in a comment, it seems possible something is wrong with your proxy server. Can you make the request without it? If so, try that.
You also might try using the command line program called curl to make a similar request. curl --verbose will chatter about what it does, letting you see some details about what is failing. You didn't give us enough information to allow a detailed suggestion about how to use curl. This may help with the proxy settings. performing HTTP requests with cURL (using PROXY)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | gaaaaaa |
| Solution 2 | O. Jones |
