简体   繁体   English

错误“事件处理程序”不是“处理” ECONNRESET

[英]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.我正在使用库请求发布数据,但我不断收到错误 ECONNRESET,即使我有一个错误事件处理程序。 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

Seems like .on('error', ...);好像.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) {}) N 次后无法捕获 ECONNRESET,因此解决 if(afaik 现在)的唯一方法是使用process.on('uncaughtException', function(error) {})

I hope this help other people:)我希望这对其他人有帮助:)

Wrap all the code you have using request in a try {} clause, followed by将所有使用request的代码包装在try {}子句中,然后是

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的命令行程序来发出类似的请求。 curl --verbose will chatter about what it does, letting you see some details about what is failing. curl --verbose会喋喋不休地谈论它做了什么,让你看到一些关于失败的细节。 You didn't give us enough information to allow a detailed suggestion about how to use curl .您没有向我们提供足够的信息,无法提供有关如何使用curl的详细建议。 This may help with the proxy settings.这可能有助于代理设置。 performing HTTP requests with cURL (using PROXY) 使用 cURL 执行 HTTP 请求(使用 PROXY)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM