create-boom-error
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 errormessage
- 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 instanceof MyError
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.message
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.
var createBoomError = require('create-boom-error').bind(exports);
createBoomError('TestError', 400, 'test message');
This error is automatically exported in customError.js
:
var CustomErrors = require('./customErrors');
var err = new CustomErrors.TestError();
err instanceof CustomErrors.TestError
TODO