Simple way to extend JS Error class with custom code or default message.
npm install --save error-extend
const errorExtends = require('error-extend');
const MyCustomError = errorExtends({ name: 'MyCustomError', code: 418, defaultMessage: 'I am a teapot' });
throw new MyCustomError();
throw new MyCustomError('I am a wonderfull teapot');
name
, the name of the error classcode
, default code of the errordefaultMessage
, default message of the error is none is provided on Error instanceinit
: an init function with error to custom on settings
MIT