user578895
user578895

Reputation:

Not wanting promises to swallow errors

I'm switching some code from bluebird to native Promises and am getting rather annoyed at the fact that native promises swallow errors even when there's not a .catch() defined. It makes debugging impossible unless you put a catch() on every promise.

So my question -- Does anyone have a solution to this? Possibilities include some way to tell promises to throw, or a way to globally catch them, or...?

Upvotes: 2

Views: 284

Answers (1)

Benjamin Gruenbaum
Benjamin Gruenbaum

Reputation: 276596

I wrote and Petka (bluebird's author) implemented (we had help :)) this functionality for Node a little back. I don't think you should switch from bluebird (it's faster and has a richer API) but if you want - use the rejection hooks:

process.on('unhandledRejection', function(p, reason) {
    // handle error here, all "swallowed" errors get here
});

This requires io.js 1.4+ or modern NodeJS (3.0+), this won't work in node 0.12, so better use a modern version or just keep using bluebird (which is also compatible with this event)

Upvotes: 3

Related Questions