throw new错误无法使用res.json()设置标头

时间:2016-06-16 02:09:39

标签: javascript node.js

之前我遇到过这个问题,我知道它可能是由多个res.json引起的,但在这种情况下我想知道为什么它有错误

router.post('/', function(req, res) {

  var data = {
    username: req.body.username,
    password: req.body.password
  };
Owner.getUser(data,function(err,response){
    if(err)
        throw err

    if(response){

        console.log(response.password);
        var createHash = function(password){
            return bCrypt.hashSync(password, bCrypt.genSaltSync(10), null);
        };

        Owner.comparePassword(response.password, createHash(data.password) , function(err, result){

            if(result === true){

             res.json({msg: 1});

            }else{
              res.json({msg: 'Error, Incorrect password!'});
            }
        });

    }else{
        res.json({msg: 'No such account exists! '});
    }
  });

有什么想法吗?

0 个答案:

没有答案