在 Q 中记录所有拒绝承诺

Log all reject promises in Q

有没有办法配置 Q 以记录或调用所有被拒绝的承诺的特定函数(如拦截器)?

我的应用程序中吞噬了许多异常,将错误处理放在我的所有承诺中只是为了记录目的将是重复的工作。

谢谢!

Q 实际上已经支持这个 - 从 1.3.0 开始 Q 提供 standard unhandled rejection hooks:

process.on("unhandledRejection", function(reason, p) {
  console.log("Unhandled rejection detected ", reason, p);
});

您还可以登录caught errors from .done with Q.onerror:

Q.onerror = function(error){
    // errors will be here and not thrown in `done` chains.
};