Bluebird.js のカスタム エラー ハンドラを使用しようとしています。
以下の例では、MyCustomError ハンドラーではなく、catch-all ハンドラーが呼び出されますが、拒否をthen関数に移動した (そして 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;