Nodejs:如何从中间件中捕获异常?

时间:2010-10-31 15:44:31

标签: node.js express less

我正在使用node.js和“less”编译器中间件:

app.configure(function() {
    // ...
    app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }))
    // ...
})

现在我有一个有问题的.less - 文件,但我找不到任何关于如何获取错误消息的文档。 我收到的页面是:

<html>
  <head>
    <title>[object Object]</title>
    <style>
      /* css stuff */
    </style>
  </head>
  <body>
    <div id="wrapper">
      <h1>Connect</h1>

      <h2><em>500</em> [object Object]</h2>
      <ul id="stacktrace"></ul>
    </div>
  </body>
</html>

所以这没有用。有人有个主意吗?

1 个答案:

答案 0 :(得分:4)

啊,好的,明白了。诀窍是放弃开发errorHandler

app.configure('development', function() {
    // app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

似乎吞下了对app.error的调用,所以现在这样做了:

app.error(function(err, req, res, next) {
    sys.puts("APP.ERROR:" + sys.inspect(err));
    next(err);
});

这显示正确的错误而不是[object Object]

相关问题