I'm trying to .catch() specific errors from another promise and the following doesn't work:
...
.catch(MyCustomError, (err) => {
// this block doesn't get called
})
.catch((err) => {
// this block is called instead
console.log(err instanceof MyCustomError) // false
})
using the same block of code but with Bluebird the block is executed as expected.
Any thoughts?
@teckays Per spec, Promise.prototype.catch() accepts only one argument — the onRejected callback.
What Bluebird does is an non-standard extension, similar to Bluebird.promisifyAll().
@ChALkeR I would still not close this issue based on the second .catch() block because the instance of the err returned by my other promise is changed when proxied back to my initial Promise chain. So if I do:
...
.catch((err) => {
console.log(err) // [TypeError: Cannot set property 'message' of undefined]
console.log(err instanceof MyCustomError) // false
})
so this would definitely be a good topic for discussion.
ok @ChALkeR never mind, had a completely new test written from scratch to test this bug in particular and looks like it's not from Promise. Thanks.
Following standards makes all modern JavaScript engines very obsolete unfortunately. Bluebird is the best Promise library, I've no idea why V8 developers didn't get it as the _standard_. Design by committee vs most stars and developers satisfaction...
Relying on manual error handling can eat a lot of time. See https://stackoverflow.com/questions/42064466/instanceof-using-es6-class-inheritance-chain-doesnt-work and
https://github.com/babel/babel/issues/4058 for examples of why Bluebird is so good.