🔧 Add custom options to Restify's errors!
DEPRECATED!!!
$ npm install --save restify-errors-options
const errorsOptions = require('restify-errors-options');
// Is extremely important to require restify-errors-options before restify.
const errors = require('restify-errors');
// Default behaviour
const err1 = new errors.NotFoundError({errno: 'NFE'});
console.log(err1.toJSON());
//=> {code: 'NotFound', message: ''}
// Add errno as option to add to the body
errorsOptions.add('errno');
const err2 = new errors.NotFoundError({errno: 'NFE'});
console.log(err2.toJSON());
//=> {code: 'NotFound', message: '', errno: 'NFE'}
console.log(err1.toJSON());
//=> {code: 'NotFound', message: ''}
// Restore the default behaviour
errorsOptions.delete('errno');
const err3 = new errors.NotFoundError({errno: 'NFE'});
console.log(err3.toJSON());
//=> {code: 'NotFound', message: ''}
console.log(err2.toJSON());
//=> {code: 'NotFound', message: '', errno: 'NFE'}
console.log(err1.toJSON());
//=> {code: 'NotFound', message: ''}Community packages that implement adds options through this package. If you want yours listed here open a PR.
- restify-errors-options-errno: Add errno to Restify's errors
Adds custom options to errors' body.
Type: string
Name of the option key to add.
Type: (number|boolean|string|object)
Default value for the option. You can also provide a function, see the next section.
Type: function
Returns the default value for the option using parameters of the error.
Removes previously added custom options..
Type: string
Name of the option key to remove.
- Simone Primarosa - simonepri
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details.