New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

hapi-boombox

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-boombox

Boom error wrapper


Version published
Weekly downloads
53
increased by341.67%
Maintainers
1
Weekly downloads
 
Created

Hapi-Boombox Build Status

Hapi error conversion and logging

What

Boombox logs errors and is able to transform errors. Boombox logs errors, see below.

How

Provide Boombox with custom errors when registering. (Optional) an it will convert errors with messages that match a key in errors and will return a new Boom error.

    var Errors = require('./test/config/errors.json'); //Look here for an example!
    server.register({
        register: require('hapi-boombox'),
        options: { errors: Errors }
    }, callback);

E.g. you return new Error('RESOURCE_NOT_FOUND') and the config states that this should return a Boom.notFound (404). Boombox will do that for you instead of returning an internal server error.

Loging

Both methods will do a server.log with hapi-boombox as tag and the result as data.

  • error: the original error
  • stack: the stacktrace
  • request: additional info about the request
    • path, query, method, payload, headers, request.info, credentials
      • credentials: if present this will be an object that includes 2 properties from request.auth.credentials.
        • id and name.
        • These are properties required by the author for his project. If you want more or something custumizable make an issue or PR.

Test

100% test coverage! Also look in the tests for more examples.

Notes

Personally I use this in a Hapi server to use generic keys as errors in my code but to give the end user a decent error message and to easily match errors with the right error code. Maybe in the future this can also return localized errors.

FAQs

Package last updated on 28 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts