Node.js 一次显示所有错误NodeJS

Node.js 一次显示所有错误NodeJS,node.js,Node.js,当comparePassword不正确以及req.check插入不正确时,我曾遇到显示错误问题。拜托,有人能帮我改进一下吗 router.put('/changePassword', function (req, res, next) { User.comparePassword(req.body.old, req.user.password, function (err, isMatch) { req.check('old', 'Old password is required').notE

当comparePassword不正确以及req.check插入不正确时,我曾遇到显示错误问题。拜托,有人能帮我改进一下吗

router.put('/changePassword', function (req, res, next) {

User.comparePassword(req.body.old, req.user.password, function (err, isMatch) {
req.check('old', 'Old password is required').notEmpty();
req.check('new', 'New password is incorrect').isLength({ min: 4 }).equals(req.body.newConfirm);

  var errors = req.validationErrors();


      if (err) throw err;
      if (isMatch) {
          bcrypt.hash(req.body.new, saltRounds, function (err, hash) {
          if (err) {
            console.log(err)
          } else {
              var newPassword = hash;
                  User.findOneAndUpdate({ _id: req.user._id },
                    {
                      $set: { 
                        password: newPassword,
                      }
                    },
                    {
                      upsert: true
                    },
                    ((newPassword) => {
                      res.send(newPassword)
                    })
                  )
                } 
    })

  } else {
        res.json('Old password is wrong')
  }}
  )})

如果(err)错误不是null或未定义的(或者相反),则必须在
中进行检查,然后可以创建一个包含错误的变量(带有
{error,errors}
?)并抛出它