-
Notifications
You must be signed in to change notification settings - Fork 192
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
Added a method to extend output error #47
Conversation
refactor to extend
refactor to extend
I'm not sure how useful this is, but either way, there must be a nicer function name... |
I think it's useful in some contexts for an API to return errors with additional information, like an internal error code. Let's say for example that a database finds a duplicate username while creating one, and the ORM throws an error. You might want the API to return en error , with an internal |
I'll let @arb decide. |
@@ -45,6 +45,9 @@ internals.initialize = function (error, statusCode, message) { | |||
error.reformat = internals.reformat; | |||
error.reformat(); | |||
|
|||
error.extendOutput = internals.extendOutput; | |||
error.extendOutput(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you calling it here? Doesn't look like it's doing anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true. useless.
Few other things
|
I think it comes down to flavour. I personally think it's more way verbose this code: var boom = Boom.forbidden( "Username already exists" );
boom.output.payload.errorCode = "duplicatedUsername";
reply( boom ); than this one: reply( Boom.forbidden("Username already exists.").extendOutput({errorCode: "duplicatedUsername"}) ); Now, as a second thought, the main use case here is, like in the example, to add an internal errorCode. Perhaps the balance between simplicity and expressivity here is to rename the method to Just openly tell me if u think it's worth adding this method or not, and I'll fix the rest. A no go here is understandable. |
@arb Comments? |
I think we'll pass on this right now. We can re-examine this if more people ask for it. Doesn't seem useful enough to justify changing the API. Thanks for contributing. Lots of other things you can do in the hapijs world if you're looking for more open source work 😄 |
Thanks @arb. Fully understand. We're building our first project with hapijs and we're very very happy with it. We'll be happy to contribute where we humbly can. |
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. |
Use case: To take advantage of Boom and at the same time send custom data to the output object, you must manually attach properties to the the_output.payload_ boom instance. The following code is more elegant and chainable:
Boom.forbidden('My message').extendOutput({customError: 123});