javascript 如何阻止错误“读取 ECONNRESET”的发生

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54408047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 10:23:42  来源:igfitidea点击:

How to stop the error 'read ECONNRESET' from happening

javascriptnode.jsdiscorddiscord.js

提问by GamesProSeif

I've made a lot of bots, hosted some on my personal laptop, and some on Heroku, but in both, I received this error that terminated node.js, so I used bot.on('error', console.error)to view the error and here's the result:

我已经制作了很多机器人,在我的个人笔记本电脑上托管了一些,在 Heroku 上托管了一些,但是在这两种情况下,我都收到了终止 node.js 的错误,所以我曾经bot.on('error', console.error)查看过错误,结果如下:

type: 'error', message: 'read ECONNRESET', error: {
  Error: read ECONNRESET at TLSWrap.onStreamRead(internal / stream_base_commons.js: 111: 27) errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read'
}

If anyone knows how to stop that from happening, please tell me.

如果有人知道如何阻止这种情况发生,请告诉我。

回答by Ashish

"ECONNRESET" usually happens when another end of the TCP connections closes its end due to any protocol-related errors and since no one is listening to the 'error' event it gets thrown, to deal with it you should put a listener which can handle such erroneous condition.

“ECONNRESET”通常发生在 TCP 连接的另一端由于任何与协议相关的错误而关闭其端时,并且由于没有人在侦听它抛出的“错误”事件,要处理它,您应该放置一个可以处理的侦听器如此错误的状态。

You can refer to such exception handling here node-js-best-practice-exception-handling

你可以在这里参考这样的异常处理node-js-best-practice-exception-handling