美文网首页
node.js的express框架怎么捕获异常

node.js的express框架怎么捕获异常

作者: 木子川页心 | 来源:发表于2019-04-03 14:49 被阅读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')
})

相关文章

网友评论

      本文标题:node.js的express框架怎么捕获异常

      本文链接:https://www.haomeiwen.com/subject/czczbqtx.html