【问题标题】:How can I get stack traces from restify when I have errors in my code?当我的代码中有错误时,如何从 restify 获取堆栈跟踪?
【发布时间】:2015-09-21 08:35:12
【问题描述】:

假设我已经定义了以下 restify 端点:

server.get('/test/1', function (req, res, next) {
    undefinedFunctionCall(); // Will cause exception
    return next();
}

如何在我的服务器控制台中获取堆栈跟踪,告诉我undefinedFunctionCall 未定义? client 得到它但不是服务器。

我在the docs 中读到,您可以收听事件InternalServerErrorInternalError,但在我测试时没有发生火灾。我必须做什么?

代码:

server.on('InternalServerError', function (req, res, err, cb) {
    console.log('INTERNAL ERROR!'); // Never executed
    return cb();
});

我在 Windows 10 的节点 0.10.33 上运行 Restify 4.0.0

【问题讨论】:

    标签: node.js restify


    【解决方案1】:

    嗯,这似乎在 4.0.0 版本中有所改变。我还在使用 0.10 版本,堆栈跟踪会自动输出到服务器控制台。

    不过,试试我从this post 收集到的这个解决方案。我试过了,它对我有用。

    server.on('uncaughtException', function (req, res, err, cb) {
        console.log(err);
        return cb();
    });
    

    这与服务器死机并不完全相同,但至少你得到了堆栈跟踪。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      • 2014-08-20
      • 2017-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多