Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create-boom-error

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-boom-error

Simply create sub-classed Boom errors for Hapi applications.

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
494
increased by62.5%
Maintainers
1
Weekly downloads
 
Created
Source

create-boom-error

npm version Build Status A simple Node.js library for easily creating classed Boom errors in Hapi applications.

Installation

npm install create-boom-error

Usage

createBoomError(name, statusCode, [message])

Creates a Boom error.

  • name - The name of the error.
  • statusCode - the integer status code of the Boom error
  • message - an optional string or function which returns a string

Create a simple error

var createBoomError = require('create-boom-error');

var MyError = createBoomError('MyError', 404, 'simple message');

var err = new MyError();

// err is an instance of MyError making it easy to check in tests
err instanceof MyError // => true

Create an error with a dynamic message

var MyError = createBoomError('MyError', 404, function (num) {
  return 'You must have more than ' + num + ' coins.';
});

var err = new MyError(4);

// err now has the dynamic message
err.message // => 'You must have more than 4 coins.'

Automatically exporting an error

This is a useful shortcut if you have a file in your application where you want to declare all your errors and automatically export them. Simply call .bind(exports) when requiring the create-boom-error library.

// in customErrors.js
var createBoomError = require('create-boom-error').bind(exports);

createBoomError('TestError', 400, 'test message');

This error is automatically exported in customError.js:

// in another file
var CustomErrors = require('./customErrors');

var err = new CustomErrors.TestError();

err instanceof CustomErrors.TestError // => true

TODO

  • Add to Travis
  • Push to NPM

Keywords

FAQs

Package last updated on 27 Mar 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc