【问题标题】:Bluebird catch err logging syntax?Bluebird 捕获错误的日志记录语法?
【发布时间】:2014-09-03 00:55:47
【问题描述】:

什么是等价的 Bluebird promise err logging to this:

    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
});

【问题讨论】:

    标签: node.js error-handling mongoose promise bluebird


    【解决方案1】:

    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-10-16
    • 2012-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-30
    相关资源
    最近更新 更多