Does the special Bluebird.js error capture function not apply to the first promise?

I am trying to use custom Bluebird.js error handlers.

The following example calls the catch-all handler, not the MyCustomError handler, but when I moved the deviation to the then function (and enabled firstPromise ...), the MyCustomError handler is called. Why is this? something is wrong? Thanks.

var Promise = require('bluebird'), debug = require('debug')('main'); firstPromise() .then(function (value) { debug(value); }) .catch(MyCustomError, function (err) { debug('from MyCustomError catch: ' + err.message); }) .catch(function (err) { debug('From catch all: ' + err.message); }); /* * Promise returning function. * */ function firstPromise() { return new Promise(function (resolve, reject) { reject(new MyCustomError('error from firstPromise')); }); } /* * Custom Error * */ function MyCustomError(message) { this.message = message; this.name = "MyCustomError"; Error.captureStackTrace(this, MyCustomError); } MyCustomError.prototype = Object.create(Error.prototype); MyCustomError.prototype.constructor = MyCustomError; 
+6
source share
1 answer

Declare the error class before anything else and it will work (prototype assignments do not rise)

+4
source

Source: https://habr.com/ru/post/972242/


All Articles