Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boom.wrap never sends custom message to client #142

Closed
paulodiovani opened this issue Jan 31, 2017 · 2 comments
Assignees
Labels
bug
Milestone

Comments

@paulodiovani
Copy link

@paulodiovani paulodiovani commented Jan 31, 2017

Are you sure this is an issue with hapi or are you just looking for some help?

Yes. It's an API issue and related to #116.

I'm considering that:

  1. For 4xx and 5xx (but not 500) Errors, the message argument is always sent in the response for the client
  2. For 500 Errors, the message is hidden, sending always "An internal server error occurred" to client response
  3. Boom.wrap decorates an standard error with an optional statusCode (default to 500) and message.

What are you trying to achieve or the steps to reproduce?

I'm trying to wrap standard errors to send to client, being ale to define the correct statusCode and message.

I'm using wrap instead of other Boom methods because I still have to log the original error message.

What was the result you received?

Wrapping errors as 500 errors works as expected as follows.

> Boom.wrap(new Error('Original msg'), 500, 'Custom message')
{ Error: Custom message: Original msg
    at repl:1:11
    at sigintHandlersWrap (vm.js:22:35)
    at sigintHandlersWrap (vm.js:96:12)
    at ContextifyScript.Script.runInThisContext (vm.js:21:12)
    at REPLServer.defaultEval (repl.js:313:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:503:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:188:7)
  isBoom: true,
  isServer: true,
  data: null,
  output:
   { statusCode: 500,
     payload:
      { statusCode: 500,
        error: 'Internal Server Error',
        message: 'An internal server error occurred' },
     headers: {} },
  reformat: [Function] }

However, wrapping an error as a 4xx error sends the original error message to user and the custom message is only (able to be) logged (same for > 500 errors).

> Boom.wrap(new Error('Original msg'), 422, 'Custom message')
{ Error: Custom message: Original msg
    at repl:1:11
    at sigintHandlersWrap (vm.js:22:35)
    at sigintHandlersWrap (vm.js:96:12)
    at ContextifyScript.Script.runInThisContext (vm.js:21:12)
    at REPLServer.defaultEval (repl.js:313:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:503:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:188:7)
  isBoom: true,
  isServer: false,
  data: null,
  output:
   { statusCode: 422,
     payload:
      { statusCode: 422,
        error: 'Unprocessable Entity',
        message: 'Original msg' },
     headers: {} },
  reformat: [Function] }

What did you expect?

  • If statusCode is 500, the message is hidden from the client.
  • If the statusCode is a 4xx or > 500, the error message is sent to the user.
  • If a custom message is provided, the custom message is sent to the user and original is hidden.

I don't see any use of the message argument of Boom.wrap if it isn't to send a custom message to the client for 4xx errors while hiding the original message.

Context

Tested with

  • boom@3.2.2
  • boom@4.1.0
@hueniverse

This comment has been minimized.

Copy link
Member

@hueniverse hueniverse commented Mar 21, 2017

This should not be supported. Wrap is not meant to take a boom object and mess with it.

@zaggino

This comment has been minimized.

Copy link

@zaggino zaggino commented Mar 26, 2017

@hueniverse Isn't 3aa4a8c a breaking change which should raise major version?
Before commit .wrap on Boom was a no-op and now it throws an error through assert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.