Bluebird.js Кастомная функция ловушки ошибок, не относится к первому обещанию?
Я пытаюсь использовать пользовательские обработчики ошибок Bluebird.js.
В приведенном ниже примере вызывается универсальный обработчик, а не обработчик MyCustomError, но когда я переместил отклонение взатем функции (и разрешил firstPromise ...), вызывается обработчик MyCustomError. Это почему? что-то не так? Благодарю.
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;