How to catch a global error with NodeJS

我们两清 提交于 2019-11-29 11:46:24
Ross The Boss

ECONNRESET means that the other side of the TCP connection is aborted. You could look at the server logs, but since it was random times this makes me think that the server becomes overloaded and kills a few connections.

If you're starting a process at any point in the process try the below:

process.on('uncaughtException', function (err) {
  console.error(err.stack);
  console.log("Node NOT Exiting...");
});

attach a

request.on('error', function(err) {
    // Handle error
});

to your requests.

You can also catch uncaught errors for the process:

process.on('uncaughtException', function(err) {
  console.log('Caught exception: ' + err);
});

This error as it reads states the connection was reset, so its definitely one of the requests.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!