node.js - Bluebird 捕获错误记录语法?

标签 node.js error-handling mongoose promise bluebird

什么是等效的Bluebird Promise错误记录到此:

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

最佳答案

蓝鸟会自动为您记录未处理的拒绝。如果您希望对错误发送服务器响应并将该链标记为已处理,则可以执行以下操作:

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

关于node.js - Bluebird 捕获错误记录语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24713988/

相关文章:

ajax - 将数据从服务器(nodejs)发送到客户端(ajax请求)

javascript - 如何执行使用 AND 和 OR 的条件 Mongoose 查询?

javascript - 为什么我在 console 中打印 mongoose 的模型对象时看到额外的字段。我正在将 Node JS 与 Mongoose 一起使用。我怎样才能隐藏这些属性

javascript - 在 socket.io 中向套接字添加变量

python-3.x - 错误处理函数的有效方法

node.js - 不同步服务器响应

javascript - 一种从 Node.js 调用 execl、execle、execlp、execv、execvP 或 execvp 的方法

php - 如何捕获 php 中不存在的子对象引发的错误?

java - 登录JAVA时出错

node.js - 如何在重置密码时使用新密码更新密码