如果我在调用服务时抛出GeneralError,如何使错误对象像我想要的那样:
{
"status": "Failed",
"code": "500_1",
"detail": "Something is wrong with your API"
}
我已经尝试将其添加到错误钩子上
hook => {
hook.error = {
"status": "Failed",
"code": "500_1",
"detail": "Something is wrong with your API"
}
return hook
}
但是仍然不能,并且仍然返回羽毛的默认错误对象:
{
"name": "GeneralError",
"message": "Error",
"code": 500,
"className": "general-error",
"data": {},
"errors": {}
}
所有羽毛错误都可以通过自定义消息提供,该消息将覆盖有效负载中的默认消息:
throw new GeneralError('The server is sleeping. Come back later.');
您还可以传递其他数据和/或错误。全部记录在案:https://docs.feathersjs.com/api/errors.html