500错误统一处理

配置

app.use(router)
//放在路由后面
// 统一处理500错误 四个参数一个都不能少
app.use((err,req,res,next)=>{
    res.status(500).json({
        error:err.message
    })
})

使用

 try{

 }catch(err){
    next(err)
 }

猜你喜欢

转载自blog.csdn.net/zhong242526/article/details/80373568