Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
create-boom-error
Advanced tools
A simple Node.js library for easily creating classed Boom errors in Hapi applications.
npm install create-boom-error
createBoomError(name, statusCode, [message], [code])
Creates a Boom error.
name
- The name of the error.statusCode
- the integer status code of the Boom errormessage
- an optional string or function which returns a stringcode
- an optional machine-keyable error status stringconst { createBoomError } = require('create-boom-error');
const MyError = createBoomError('MyError', 404, 'simple message', 'not_found');
const err = new MyError();
// err is an instance of MyError making it easy to check in tests
err instanceof MyError // => true
// err.code will match the code argument passed in
err.code // => 'not_found'
Note that if the optional code
argument is NOT passed in then the .code
field attached to the error will default to a decamelized, snake case version of the name
. For example:
const MyError = createBoomError('MyError', 404, 'simple message');
const err = new MyError();
// err is an instance of MyError making it easy to check in tests
err instanceof MyError // => true
// err.code will return the name argument decamelized and in snake case
err.code // => 'my_error'
const MyError = createBoomError('MyError', 404, (num) => `You must have more than ${num} coins.`);
const err = new MyError(4);
// err now has the dynamic message
err.message // => 'You must have more than 4 coins.'
npm run test
FAQs
Simply create sub-classed Boom errors for Hapi applications.
The npm package create-boom-error receives a total of 493 weekly downloads. As such, create-boom-error popularity was classified as not popular.
We found that create-boom-error demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.