2011-10-10 51 views

回答

1
// Add an error handling as last piece of middleware 
app.use(function(err, req, res, next) { 
    res.render("404"); 
}); 

有一種特定的錯誤處理的中間件此express.errorHandler

+0

獲得一個「對象#還沒有呈現方法」錯誤 – user971956

+0

@ user971956我忘了參數的順序,固定它現在。 '(err,req,res,next)' – Raynos

+0

很好,謝謝! – user971956

2

您應該使用app.error(),如the guide中所述。

app.get('/error', function(req, res, next){ 
    throw new Error('oops'); 
}); 
app.error(function(err, req, res, next){ 
    // do whatever you want 
}); 
相關問題