node.js的express框架怎么捕获异常
2019-04-03 本文已影响0人
木子川页心
捕获异常的精髓就是不让服务器crash掉,抛出500状态
1.uncaughtExrection
2.try-catch
3.express包装
app.use(function(err,req,res,next){
res.locals.message = err.message
res.locals.error = req.app.get('env')==='development'?error
res.status(err.status||500)
res.render('error')
})