custom-err

0.0.2 • Public • Published

custom-err

Easily create an error object with custom properties attached.

API

Err(message, properties)

Usage

var Err    = require('custom-err'),
    assert = require('assert');
 
// the first argument represents the error message
// the second argument represents the custom properties object
var myErr = Err('NotFound', { code: 404 });
 
assert.equal(myErr.message, 'NotFound');
assert.equal(myErr.code, 404);

Why?

Because I found myself often writing code like this:

var err = new Error('Not Found');
err.code = 404;
err.someProperty = true;

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i custom-err

Weekly Downloads

8

Version

0.0.2

License

MIT

Last publish

Collaborators

  • alessioalex