If you're on the server-side, you can use the promise rejection hooks. These will work on most promise implementations on the server-side (io.js, bluebird, when, etc):
process.on("unhandledRejection", function(promise, reason){
// deal with the rejection here.
});
If you're in a browser environment, things are less standardised. However, When still provides similar hooks there:
window.addEventListener('unhandledRejection', function(event) {
event.preventDefault(); // This stops the initial log.
// handle event
event.detail.reason; // rejection reason
event.detail.key; // rejection promise key
}, false);
There are also local rejection hooks, these are good if you only want to handle rejections of a single instance of the promise library - this is typically useful for when building a library yourself:
var Promise = require('when').Promise;
Promise.onPotentiallyUnhandledRejection = function(rejection) {
// handle single instance error here
};