我使用了bluebird promise和standard-error。问题是当我抛出像这样的错误时
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){
})发布于 2017-02-12 14:39:05
每次导致问题时都创建新的PromiseReturns。我已经将我所有的代码捆绑在一个单独的promise中,这是可行的。
例如:
function requestFromController(body){
return new PromiseReturns(function (resolve, reject) {
if(body){
reject(new StandardError({
status: 'Error',
message: "Not Found",
originalError: err,
code: 404
}));
}
db.model.find().then(x => {
resolve(x);
})
});
}发布于 2017-01-20 17:21:29
这对我很管用。看看这个
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 caughthttps://stackoverflow.com/questions/41759680
复制相似问题