我有一個下面的Restify自定義錯誤,它被引發到我的BlueBird Promise catch塊。Restify返回undefined不是錯誤對象中的函數
var test = function() {
respObject = { hello: { world: 'aasas' } };
throw new restify.errors.ServiceError(respObject, 422);
}
然後在服務錯誤:
function ServiceError(respObject, statusCode) {
restify.RestError.call(this, {
restCode: 'ApiError',
statusCode, statusCode,
message: 'Api Error Occurred',
constructorOpt: ServiceError,
body: {
message: 'Api Error Occurrede',
errors: respObject.toJSON()
}
});
this.name = 'CustomApiError';
}
util.inherits(ServiceError, restify.RestError);
restify.errors.ServiceError = ServiceError;
但是對
test()
調用函數
:
test().catch(function(err) {
console.log(err);
});
它返回undefined is not a function
。是否有一個原因,爲什麼它不返回到catch塊的上述調用函數的對象?
會發生什麼 - 是它正常工作?我不明白你如何得到'undefined不是一個函數'.. –
@AndreyPopov如果我去拋出新的錯誤('測試')'我得到正確的錯誤對象。這只是與Restify自定義錯誤,似乎並不工作 –