8.1.0 • Published 3 years ago

hapi-boombox v8.1.0

Weekly downloads
718
License
MIT
Repository
github
Last release
3 years ago

Hapi-Boombox Build Status

Hapi error conversion and logging

What

Boombox logs errors and is able to transform errors. Current version targets hapi 16.

How

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

    const Errors = require('./test/config/errors.json'); //Look here for an example!
    await server.register({
        plugin: 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. Look at the test example to see what the config night look like.

Boombox also provides a server and request method (server.boombox(), request.boombox()) so you can transform your errors on the go. Returns undefined when matching fails.

    const matched = server.boombox(new Error('RESOURCE_NOT_FOUND'));
    /*
    * matched
    *{
    *    message: 'Custom error message for RESOURCE_NOT_FOUND',
    *    type: 'notFound'
    *}
    */

You can disable the logging part by setting disableLog to true.

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

Logging

Boombox will do a request.log with hapi-boombox and error as tags and the result as data.

  • error the output of the 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.
        • These are properties required by the author for his project. If you want more or something customizable 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.

8.1.0

3 years ago

8.0.2

3 years ago

8.0.0

4 years ago

7.0.0

5 years ago

6.0.4

7 years ago

6.0.3

7 years ago

6.0.2

7 years ago

6.0.1

8 years ago

6.0.0

8 years ago

5.5.1

8 years ago

5.5.0

8 years ago

5.4.0

8 years ago

5.3.1

8 years ago

5.3.0

8 years ago

5.2.0

8 years ago

5.1.0

8 years ago

5.0.0

8 years ago

4.2.2

8 years ago

4.2.1

8 years ago

4.2.0

8 years ago

4.1.1

8 years ago

4.1.0

8 years ago

4.0.0

9 years ago

3.1.2

9 years ago

3.1.1

9 years ago

3.1.0

9 years ago

3.0.0

9 years ago

2.2.0

9 years ago

2.1.0

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

1.1.5

9 years ago

1.1.4

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago