Hello!
Most of the Boom methods get an additional (optional) data property, what Hapi doesn't send forward in the response.
I tried using the Hapi response/tail events, but couldn't find the given data in the inputs of those events.
To add the data property:
var err = require('boom').create(451, "Msg", {name: "name"});
err.output.payload.data = err.data;
res(err);
Which is a bit more code than it is needed to write:
res(require('boom').create(451, "Msg", {name: "name"}));
The solution proposed in #47 works for me as well (as well as the data property could be used instead of the solution proposed there).
The use case is the following:
I want to send error messages, which messages should be translated on the frontend. So the message would be like an error code, and the parameters for that code would be in the data object
So a real example could be the following:
res(require('boom').create(422, "ERRORS.MUST_BE_SET", {entityName: "user", fields: ['name','email']}));
And the response for this would be preferred:
{
"statusCode": 422,
"error": "Unprocessable Entity",
"message": "ERRORS.MUST_BE_SET",
"data": {
"entityName": "user",
"fields": ["name","email"]
}
}
Thx
Adam
ps.: I might be not aware of some functionality in hapi/boom, if this is the case, pls point the existing functionality out for me