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); }); function firstPromise() { return new Promise(function (resolve, reject) { reject(new MyCustomError('error from firstPromise')); }); } function MyCustomError(message) { this.message = message; this.name = "MyCustomError"; Error.captureStackTrace(this, MyCustomError); } MyCustomError.prototype = Object.create(Error.prototype); MyCustomError.prototype.constructor = MyCustomError;
source share