📜  try and catch express - Javascript 代码示例

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

代码示例1
controller.getCharacters = async (req, res, next) => {
  try{
    const result = await models.Person.find({});
    res.locals.people = result;
  
    next();
  } catch (error){
    return next({
      log: `An error occurred at controller.getCharacters ${error}`,
      status: 500,
      message: { err: 'An error occurred' }
    });
  }
};