我正在使用 Bluebird promise 和标准错误。问题是当我抛出这样的错误时
return new PromiseReturns(function (resolve, reject) {
reject(new StandardError({
status: 'Error',
message: "Not Found",
originalError: err,
code: 404
}));
});
这次捕获中没有收到
.catch(StandardError , function(err){
})
相反,它是在
中收到的.catch(function(err){
})
最佳答案
这对我有用。看看这个
var Promise = require('bluebird')
var StandardError = require("standard-error")
Promise.resolve().then(function() {
throw new StandardError("Not Found", {code: 404})
}).catch(StandardError, function(e) {
console.log('custom error caught');
}).catch(function(e) {
console.log('generic caught');
})
输出:
$ custom error caught
关于javascript - BlueBird promise 中的特定错误捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41759680/