Giter VIP home page Giter VIP logo

Comments (11)

AdriVanHoudt avatar AdriVanHoudt commented on May 29, 2024

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.

dciccale avatar dciccale commented on May 29, 2024

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 datafield

from boom.

dciccale avatar dciccale commented on May 29, 2024

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.

arb avatar arb commented on May 29, 2024

@dciccale please see if this helps.

from boom.

dciccale avatar dciccale commented on May 29, 2024

@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.

dciccale avatar dciccale commented on May 29, 2024

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.

arb avatar arb commented on May 29, 2024

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.

dciccale avatar dciccale commented on May 29, 2024

@arb i'm really sorry, i finally solved it with that, really cool thx!

from boom.

dciccale avatar dciccale commented on May 29, 2024

and keep up with the good job guys, i'm never going back to express

from boom.

nakamorichi avatar nakamorichi commented on May 29, 2024

I wrapped the error simply this way:

			.catch(error => {
				const response = Boom.badRequest(error);
				response.output.payload.error = error;
				reply(response);
			});

from boom.

lock avatar lock commented on May 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.