Reputation: 883
What is the equivalent Bluebird promise err logging to this:
if (err) {
console.log(err);
res.send(err);
}
For this:
}).catch(Promise.OperationalError, function(e){
// handle error in Mongoose save findOne etc, res.send(...)
}).catch(function(e){
// handle other exceptions here, this is most likely
// a 500 error where the top one is a 4XX, but pay close
// attention to how you handle errors here
});
Upvotes: 0
Views: 501
Reputation: 276356
Bluebird will automatically log unhandled rejections for you. If you wish to send a server response on an error and mark the chain as handled you can do:
.catch(function(err){
console.log(err);
res.send(err);
throw err; // this is optional, if you don't want to mark the chain as handled.
});
Upvotes: 2