如何使用NodeJS捕获全局错误 [英] How to catch a global error with NodeJS

查看:1074
本文介绍了如何使用NodeJS捕获全局错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个未处理的错误,但不确定它是从哪里来的.我的应用程序在不同的方法中有几个http.request(options,callback).end(),其中回调的陷阱是"uncaughtException"和"error".我想知道我的哪种方法引发了这个问题.以下是我得到的错误.这是随机的.有什么想法可以追踪到这个吗?我希望可以采用某种全局方法来捕获未处理的错误.

I am getting an unhandled error but not sure where it's coming from. My app has several http.request(options, callback).end() in different methods, with the callback's trapping "uncaughtException" and "error". I'd like to know which of my methods initiated this issue. Below is the error I get. It is random. Any ideas how to track this down? I was hoping for some global way of trapping unhandled errors.

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: read ECONNRESET
    at exports._errnoException (util.js:746:11)
    at TCP.onread (net.js:559:26)

推荐答案

ECONNRESET表示TCP连接的另一端被中止.您可以查看服务器日志,但是由于它是随机次数,因此我认为服务器变得超载并杀死.

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...");
});

这篇关于如何使用NodeJS捕获全局错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆