samedi 21 février 2015

Promise doesn't return from sequelize model instance method


Vote count:

0




Whenever I call my instance method, the promise is never returned.



// user model
...
instanceMethods: {
verifyPassword: function(password, done) {
return bcrypt.compare(password, this.password, function(err, res) {
return done(err, res);
});
}
},


Test:



models.user.find(1).then(function(user) {
return user.verifyPassword(password, function(error, result) {
if(result)
return models.item.create(....);
});
}).catch(function(e) {
console.log(e);
});


Now, if the user enters a valid password but the item.create() fails, the error will NOT propagate back up to the outercatch() block. Instead, the program fails with:



Possibly unhandled SequelizeValidationError: Validation error


The problem is with verifyPassword() somehow not returning the promise.If I remove verifying, then everything will work; all errors are then caught in the catch().


Why does verifyPassword() not return anything?



asked 1 min ago







Promise doesn't return from sequelize model instance method

Aucun commentaire:

Enregistrer un commentaire