Log all reject promises in Q

折月煮酒 提交于 2019-12-11 03:15:28

问题


Is there a way to configure Q to log or call a specific function on all rejected promises (like an interceptor)?

Many exceptions are being swallowed in my application, and put error handling in all my promises just for logging purposes would be duplicated work to do.

Thanks!


回答1:


Q actually already supports this - as of 1.3.0 Q offers the standard unhandled rejection hooks:

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

You can also log caught errors from .done with Q.onerror:

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


来源:https://stackoverflow.com/questions/30830688/log-all-reject-promises-in-q

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!