2015-12-07 30 views
0

此:Express.js:響應後,錯誤不逮住

app.use(function(err,res,req,next){ 

}); 

將致力於服務器響應之前,只有當誤差,但如果誤差是res.send後此功能將不會被執行。 我該如何解決這個問題?

+0

生成/傳遞的錯誤究竟如何? – robertklep

回答

0

在Express 4的執行:

app.use(function(req, res, next) { 
    res.send('foo'); 
    throw new Error('bar'); // or `next(new Error('bar'))` 
}); 

app.use(function(err, req, res, next) { 
    console.log('err', err); 
}); 

此返回響應記錄錯誤。