Nodejs: How to catch an exception from middleware?

前端 未结 1 711
误落风尘
误落风尘 2021-01-13 08:08

I\'m using node.js and the \"less\" compiler middleware:

app.configure(function() {
    // ...
    app.use(express.compiler({ src: __dirname + \'/public\', e         


        
相关标签:
1条回答
  • 2021-01-13 08:51

    Ah, ok, got it. The trick is to leave away the development errorHandler

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

    It seems to swallow calls to app.error, so now this works:

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

    This shows the correct error instead of [object Object]

    0 讨论(0)
提交回复
热议问题