custom-err

Easily create an error with custom properties attached.

Easily create an error object with custom properties attached.

Err(message, properties)

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);

Because I found myself often writing code like this:

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

MIT