0

什么是等效的 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
});
4

1 回答 1

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.
 });
于 2014-07-12T19:07:52.260 回答