Giter VIP home page Giter VIP logo

boom's People

Contributors

adrivanhoudt avatar arb avatar bbrown avatar cjihrig avatar devinivy avatar dunnock avatar fcmam5 avatar geek avatar hueniverse avatar jarrodyellets avatar jeffbski avatar kanongil avatar kpdecker avatar lloydbenson avatar lukasolson avatar manonthemat avatar marsup avatar mastermatt avatar mcandre avatar michelbl avatar mtharrison avatar mymattcarroll avatar nargonath avatar pdehaan avatar pon avatar royshouvik avatar simon-p-r avatar toymachiner62 avatar vbardales avatar watson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

boom's Issues

Expand Unauthorized

Expand documentation for Boom.unauthorized as it is more involved than a simple 401 response.

Boom.wrap

I noticed that there is no documentation for Boom.wrap, but that it is a function of module.export.

Was this done on purpose or should Boom.wrap be documented?

Question: Recommended way to add errorCode to errors

First of all, great library really easy to use 😄.

I'd like to see if you have any recommendations on how to have fixed error codes (i.e. 'invalid_connection') that are different from the error message. I'd would like to have a fixed set of those while being able to change error messages.

For example instead of the following Boom.notFound('The user does not have an email'):

{
  "statusCode": 404,
  "message": "The user does not have an email",
  "error": "Not Found"
}

I'd would like to get something like this:

{
  "statusCode": 404,
  "message": "The user does not have an email",
  "error": "Not Found",
  "errorCode": "user_without_email"
}

Is there some way to achieve something like this? If it requires a PR let me know and I can work on it (not saying that it should require a PR, just don't want to "ask for things").

badImplementation method message missing

Hi there,

I have updated boom to the latest version and found that badImplementation method not returning custom messages anymore.

And I have looked in tests and found that test for message is also missing.

How to add message to message array in Boom

Its not an issue, I just want to know that how can make Boom message as array .
Eg. : - In boom server response is like : -

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "invalid query"
}

but i want it to like : -

{
    "statusCode": 400,
    "error": "Bad Request",
    "messages": [
                         {"text":"this is a server message or error", "severity": "warn"}
    ]
}

I can not push addition data of error to response

I want to create error that contains attr 'data' where I can push what i need

in documentation I've found method 'create'

create(statusCode, [message], [data])

but the object what I've pushed to 'data' param I' have not found in response

Expose Boom.unauthorized as a way to wrap another error

I am trying to augment some custom errors with properties from Boom.unauthorized (mainly the header) and am finding that you can't easily wrap a custom error with it. I am currently just generating a new unauthorized error with the properties I want and then using extend to attach the properties. I was hoping there would be a cleaner way to do this, like Boom.wrap does for the generic stuff.

Easy way to determine if the client or server is at fault

Wouldn't it be great if you could do:

error = Boom.notFound()
error.isClient // => true

error = Boom.notImplemented()
error.isClient // => false

What do you think?

Alternative approach:

error = Boom.notFound()
Boom.isClient(error) // => true

error = Boom.notImplemented()
Boom.isClient(error) // => false

npm install boom fails

For a 0.8.18 Node and a 1.7.71 npm .. I get numerous errors when I want to install boom

The last one is

npm ERR! cb() never called!
npm ERR! not ok code 0

.. But I had, in context of zmbie.js, which is used with cucumber.js, a "TOO MANY OPEN FILES". Not sure where to adress this. But installing boom it self seems not successful.

status code 418

Why does 418 in lib\index.js use backticks instead of quotes?

It causes uglifyjs to choke since uglifyjs does not yet support ES6.

Shouldn't 418 use quotes for consistency?

Add data property to the response object

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

Strict mode error

Through hawk for hapi, Im getting an error to boom. Im not sure if this issue is in the right place or I should post it in the hawk. The error log can be seen in the travis build and basically it complains about SyntaxError: Use of const in strict mode. How to fix this?

Boom.badImplementation error thrown when sent in HapiJS reply

Hello

It seems that no matter where i try to use

return reply(Boom.methodNotAllowed('terrible implementation'));

Node throws an error similar to this:

Debug: internal, implementation, error 
    Error: Internal Server Error
    at Object.exports.create (/Users/myuser/Documents/Dev/myProject/node_modules/boom/lib/index.js:21:17)
    at Object.exports.internal (/Users/myuser/Documents/Dev/myProject/node_modules/boom/lib/index.js:253:92)
    at Object.exports.badImplementation (/Users/myuser/Documents/Dev/myProject/node_modules/boom/lib/index.js:289:23)
    at /Users/myuser/Documents/Dev/myProject/main.js:208:35
    at /Users/myuser/Documents/Dev/myProject/models/XXUser.js:203:20
    at /Users/myuser/Documents/Dev/myProject/models/XXAccount.js:26:20
    at /Users/myuser/Documents/Dev/myProject/XX_modules/XXSQL.js:54:20
    at /Users/myuser/Documents/Dev/myProject/node_modules/mssql/lib/main.js:569:22
    at /Users/myuser/Documents/Dev/myProject/node_modules/mssql/lib/main.js:1593:20
    at Request.userCallback (/Users/myuser/Documents/Dev/myProject/node_modules/mssql/lib/tedious.js:981:59)

EDIT:
It looks like my understanding of how this is supposed to be used was incorrect. I receive errors in the debug console because that's what this Boom is supposed to do. It does not send the message you input ('terrible implementation") to the client. Instead it sends a generic internal error which is perfect.

Maybe update the docs to make this more clear?

Make sure Boom initialize method auto cast string statusCode to Integer if possible

At line

Hoek.assert(Hoek.isInteger(statusCode) && statusCode >= 400, 'First argument must be a number (400+):', statusCode);
the validation is failing if input statusCode is not of Integer type, but which can be converted to integer. Can someone please fix this issue, otherwise in consumer module previous initialization code started breaking and client is receiving 500 internal server error.

how to set/update a cookie in combination with Boom?

When I return a regular json response from a route, I can set/update a cookie via Hapi's state() like this:

return reply({error:false, result:'all went well!'}).state('session', {user:'joe'});

When using Boom, however, this doesn't work:

return reply(Boom.badRequest('invalid api call')).state('session', {user:'joe', lastfailedrequest:Date.now()});

This results in the following error:

TypeError: reply(...).state is not a function

So how can I set/update a cookie when using Boom?

Status Code Hash

Use internal memory of status codes rather than one inside http.

`npm test`: Coverage error (Windows)

When I run npm test, I get a coverage error.

Trace:

$ npm test

> [email protected] test c:\Documents and Settings\apenneba\Desktop\src\boom
> make test-cov

node node_modules/lab/bin/lab -r threshold -t 100


  ..........................

 26 tests complete (0 ms)

Coverage: 0.00%

Code coverage below threshold: 0.00 < 100
make: *** [test-cov] Error 1
npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

System:

$ specs node os
Specs:

specs 0.4
https://github.com/mcandre/specs#readme

npm --version
1.2.17

node --version
v0.10.3

systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name:                   Microsoft Windows XP Professional
OS Version:                5.1.2600 Service Pack 3 Build 2600

how to wrap a mongoose validation error

hi i am having an issue to reply a mongoose validation error.

this is the raw error

{ [ValidationError: User validation failed]
  message: 'User validation failed',
  name: 'ValidationError',
  errors: 
   { 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]' } } }

but if I want to wrap the error for example on a Boom.badData() error I get only:

{
error: "Unprocessable Entity"
message: "User validation failed"
statusCode: 422
}

I also tried using reply() sending the raw error the way is returned from mongoose, but I am not able to specify the .code(422) it says method undefined. (it works if I send a string or an object, but not an error object).

so, is there any way to wrap this with Boom without loosing important fields of the error?

Optionally render the original 500 error message

Boom defaults to hiding original 500 messages, which I think is a sensible default. However I'm building an internal app which will only be used by technical staff. If something like a db connection fails I'd much rather return the true error message.

The best way I've found to do this is to reset the message after wrapping the err, e.g.

Boom.wrap(err)
err.output.payload.message = err.message

However it's a bit ugly and I was wondering if there is a better way? What do you think about providing a mechanism for enabling this behaviour this globally?

Custom message overrided by standard message

On every Boom.badImplementation(err.message) I was expecting a specific message but I only get this:

{
  "statusCode":500,
  "error":"Internal Server Error",
  "message":"An internal server error occurred"
}

Even If I do reply(Boom.badImplementation('damn'));.

I will get the message before. And on the log I get the right message:
151017/012509.439, [error], message: damn stack: Error: damn

I'm using 2.8.0 version of this module.

What's the point of hiding the actual error from the user?

I know that some errors should not be sent from the server to the client directly since it could be unsecure.. but let me explain my situation

when replying a Boom error, I always receive a 500 statuscode error with Internal Server Error message from the server, if I can actually create Boom errors with custom messages, or prepending a custom message to the default one, how could I treat those errors which has different messages/codes in the client?

I have two layers of error handling in my server app. One layer is managed by a service which throw specific new error constructors with specific messages.

in the second layer I have my controller where I reply things to the client, in that point depending of what type of error I get from the service I reply different Boom error type with custom or default message, something useful for displaying in the client, like a validation message, or the default unauthorized message, etc.

but since all errors are replying 500 and so on.. how could I manage this?

thanks

Use captureStackTrace to remove boom artifacts from stack traces

Using this https://code.google.com/p/v8-wiki/wiki/JavaScriptStackTraceApi the boom stack traces can safely remove their own frames so:

Debug: internal, implementation, error
    Error: child "text" fails because ["text" is required]
    at Object.exports.create (/Users/user/project/node_modules/boom/lib/index.js:21:17)
    at Object.exports.internal (/Users/user/project/node_modules/boom/lib/index.js:262:99)
    at Object.exports.badImplementation (/Users/user/project/node_modules/boom/lib/index.js:298:23)
    at postValidate (/Users/user/project/node_modules/hapi/lib/validation.js:194:26)
    at [object Object].internals.Any._validateWithOptions (/Users/user/project/node_modules/joi/lib/any.js:652:16)
    at [object Object].root.validate (/Users/user/project/node_modules/joi/lib/index.js:102:23)
    at exports.response (/Users/user/project/node_modules/hapi/lib/validation.js:213:20)
    at /Users/user/project/node_modules/hapi/lib/request.js:377:13
    at iterate (/Users/user/project/node_modules/hapi/node_modules/items/lib/index.js:35:13)
    at done (/Users/user/project/node_modules/hapi/node_modules/items/lib/index.js:27:25)
    at /Users/user/project/node_modules/hoek/lib/index.js:841:22
    at process._tickDomainCallback (node.js:381:11)

Could reduce to:

Debug: internal, implementation, error
    Error: child "text" fails because ["text" is required]
    at postValidate (/Users/user/project/node_modules/hapi/lib/validation.js:194:26)
    at [object Object].internals.Any._validateWithOptions (/Users/user/project/node_modules/joi/lib/any.js:652:16)
    at [object Object].root.validate (/Users/user/project/node_modules/joi/lib/index.js:102:23)
    at exports.response (/Users/user/project/node_modules/hapi/lib/validation.js:213:20)
    at /Users/user/project/node_modules/hapi/lib/request.js:377:13
    at iterate (/Users/user/project/node_modules/hapi/node_modules/items/lib/index.js:35:13)
    at done (/Users/user/project/node_modules/hapi/node_modules/items/lib/index.js:27:25)
    at /Users/user/project/node_modules/hoek/lib/index.js:841:22
    at process._tickDomainCallback (node.js:381:11)

Which helps remove noise from throws.

Potential downsides:

  • Only works under v8
  • Slight bit of additional complexity
  • Won't impact wrap API (Probably not a downside since it's BYO Error object so the user controls the trace already

General pattern is here:
https://github.com/chaijs/chai/blob/4e18d2a49394f21f49eaea97f556d6a17ecbcc7e/chai.js#L5015
https://github.com/wycats/handlebars.js/blob/master/lib/handlebars/exception.js

Glad to do the work to PR this if desired.

What happens to the 'data' sent?

Boom.badRequest('Invalid request', {name: 'required'});

Boom never returns the data passed to the function. It only returns the output.payload. What is the use of suppling data to Boom then? Should it not be returned in the response?

Support for RFC 2324

Can we please get support for 418 HTTP Status codes as described in RFC 2324 added to Boom?

I just really need to do a Boom.iAmATeapot() ;-)

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.