Log all deviations of promises in Q

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

Many exceptions get swallowed in my application and error handling in all my log-only promises will duplicate work.

Thank!

+2


source to share


1 answer


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

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

      



You can also log to catch errors from .done

withQ.onerror

:

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

      

+3


source







All Articles