I am trying to catch errors thrown from Mongoose using Mongoose's native promises. But I don't know where to get the error object from Mongoose.
I would like the errors to be thrown in the .then()
s and caught in .catch()
if possible.
var contact = new aircraftContactModel(postVars.contact);
contact.save().then(function(){
var aircraft = new aircraftModel(postVars.aircraft);
return aircraft.save();
})
.then(function(){
console.log('aircraft saved')
}).catch(function(){
// want to handle errors here
});
Trying not to use another library, as .save() returns a promise natively.