Create new error instances with a code.
$ npm install err-code
I find myself doing this repeatedly:
var err = new Error('My message');
err.code = 'ESOMECODE';
throw err;
Simple usage.
var errcode = require('err-code');
throw errcode('My message', 'ESOMECODE');
Other custom properties
var errcode = require('err-code');
throw errcode('My message', 'ESOMECODE', { some: 'property' });
Fill error object with a code and properties
var errcode = require('err-code');
throw errcode(new Error('My message'), 'ESOMECODE', { some: 'property' });
$ npm test
Released under the MIT License.