当我的代码出现错误时,如何从restify获取堆栈跟踪?

比方说,我已经定义了以下restify端点:

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

我怎样才能得到我的服务器控制台的堆栈跟踪,告诉我, undefinedFunctionCall是未定义的? 客户端得到它,但不是服务器。

我已经阅读了文档 ,你可以听到事件InternalServerErrorInternalError ,但是当我testing时没有任何的火灾。 我必须做什么?

码:

 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

嗯,这似乎已经改变了版本4.0.0。 我仍然在版本0.10和堆栈跟踪自动输出到服务器控制台。

不过,请尝试从这篇文章中收集的这个解决scheme。 我试了一下,它适用于我。

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

它不完全一样的服务器死亡,但至less你得到一个堆栈跟踪。