Comments (11)
You can use https://github.com/hapijs/boom#createstatuscode-message-data and then send the important fields as data
otherwise I would try https://github.com/hapijs/boom#wraperror-statuscode-message
from boom.
i am trying reply(Boom.create(422, err.message, err));
however i'm still receiving the same thing on the browser or postman or network devtools whatever. where i am supposed to get that extra data
?
wrap()
doesn't help, it does the same thing as create but without this extra data
field
from boom.
also tried sending the errors
object which is the most important thing reply(Boom.create(422, err.message, err.errors));
but still getting the same basic payload
{
error: "Unprocessable Entity"
message: "User validation failed"
statusCode: 422
}
from boom.
@dciccale please see if this helps.
from boom.
@arb nope, that returns
{
error: "Internal Server Error"
message: "An internal server error occurred"
statusCode: 500
}
i would prefer returning a 422
with at least the errors
field from mongoose error.
from boom.
if I do this:
var e = Boom.whatever(err);
e
looks something like this before going through reply()
:
{ [Error: User validation failed]
data:
{ email:
{ [ValidatorError: The specified email address is already in use.]
properties: [Object],
message: 'The specified email address is already in use.',
name: 'ValidatorError',
kind: 'user defined',
path: 'email',
value: '[email protected]' } },
isBoom: true,
isServer: true,
output:
{ statusCode: 500,
payload:
{ statusCode: 500,
error: 'Internal Server Error',
message: 'An internal server error occurred' },
headers: {} },
reformat: [Function],
isDeveloperError: true }
the problem is when passing e
to the reply(e)
method of hapi, the response of the endpoint is this
{
error: "Internal Server Error"
message: "An internal server error occurred"
statusCode: 500
}
i gues I should move this issue there
from boom.
You didn't read everything I linked to. You need to do error transformation if you want to expose more data to the client than is normally there. https://github.com/hapijs/hapi/blob/master/API.md#error-transformation
from boom.
@arb i'm really sorry, i finally solved it with that, really cool thx!
from boom.
and keep up with the good job guys, i'm never going back to express
from boom.
I wrapped the error simply this way:
.catch(error => {
const response = Boom.badRequest(error);
response.output.payload.error = error;
reply(response);
});
from boom.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
from boom.
Related Issues (20)
- Add change log or release notes. HOT 1
- Optional second param for Boom.isBoom() to verify status code
- Restore support for nodejs v10? HOT 1
- Boom.wrap is not a function HOT 1
- Get optional message from response HOT 1
- output.payload.attributes is not exposed in the .d.ts file HOT 6
- Latest v7-commercial release (v7.4.11) is broken HOT 2
- @hapi/boom error HOT 2
- When returning Boom.badImplemention from an handler the isBoom property is not set on the request.response HOT 1
- Extending Boom and unexpected instanceof behavior HOT 1
- Boomify throws when using multiple versions of Boom HOT 6
- Missing Boom.notFound etc error argument type support HOT 1
- Allow "unknown" values to be boomified HOT 24
- Changelog for @hapi/boom 10.0.0 HOT 4
- [Feature] Add support for the edge runtime
- Add support for native `cause` HOT 6
- missing 10.0.1 release at https://github.com/hapijs/boom/releases HOT 2
- Missing .stack value on node 21
- Badly implemented Boom like class can cause runtime error HOT 1
- Change of Dependency Name Breaks boom HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from boom.