与此相同的Bluebird承诺错误是什么:
if (err) {
console.log(err);
res.send(err);
}
为此:
}).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
});
答案 0 :(得分:2)
Bluebird会自动为您记录未处理的拒绝。如果您希望针对错误发送服务器响应并将链标记为已处理,则可以执行以下操作:
.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.
});