Hapi不会从Boom错误返回数据属性 [英] Hapi does not return data attribute from Boom error
问题描述
从我的Hapi路线回复Boom错误时...
When replying with a Boom error from my Hapi route...
{
method: 'PUT',
path:'foo',
handler: function (request, reply) {
reply(Boom.badRequest('something', { stuff: 'and more' }));
}
}
...我收到以下回复:
... I get the following response:
{statusCode:400,error:Bad Request,message:something}
它缺少提供错误详情的数据对象!这是什么交易?
It's missing the data object which provides the details of the error! What's the deal?
推荐答案
在 Hapi文档它引用了boom对象上的 output.payload
属性,默认情况下设置为包含 statusCode
,错误
和消息
。
On the Hapi documentation it references the output.payload
property on the boom object, set by default to include statusCode
, error
and message
.
我能够通过在此对象上设置 .details
来输出繁荣错误的详细信息:
I was able to output the details from the boom error by setting .details
on this object:
{
method: 'PUT',
path:'foo',
handler: function (request, reply) {
var err = Boom.badRequest('something', { stuff: 'and more' });
err.output.payload.details = err.data;
reply(err);
}
}
不是世界上最理想的东西,但可能一个安全的默认值。
Not the most ideal thing in the world, but probably a safe default.
这篇关于Hapi不会从Boom错误返回数据属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!