Hapi does not return data attribute from Boom error

When responding 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 answer:

{"statusCode":400,"error":"Bad Request","message":"something"}

Missing data object that contains error information! What a deal?

+6
source share
2 answers

In the Hapi documentation, it refers to the output.payload property of the arrow object; the default is statusCode , error and message .

I was able to infer data from an arrow error by setting .details to 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 safe by default.

+11
source

I had the same question, and although I cannot take the approach you took, in the Frequently Asked Questions about Arrows

Question How do I include additional information in my answers? output.payload missing data, what gives?

The answer . It is clear that the values ​​returned to the response load are quite closed. This is mainly for security and non-important information is returned to the client. This means that you will need to make a little more effort to include additional information about your custom error. Check out the “Conversion Error” section of the hapi documentation.

AND

I found that (oddly enough), according to the docs answer (but not using an example), sending a message to badImplementation ignored, while sending a message to notImplemented is both 5xx errors.

Documents for: badImplementation vs notImplemented

+1
source

Source: https://habr.com/ru/post/979556/


All Articles