📜  默认错误处理程序 express - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:08.080000             🧑  作者: Mango

代码示例1
app.use((err, req, res, next) => {
  const defaultErr = {
    log: 'Express error handler caught unknown middleware error',
    status: 500,
    message: { err: 'An error occurred' },
  };
  const errorObj = Object.assign({}, defaultErr, err);
  console.log(errorObj.log);
  return res.status(errorObj.status).json(errorObj.message);
});