https://github.com/simonepri/restify-errors-options
🔧 Add custom options to Restify's errors
https://github.com/simonepri/restify-errors-options
restify restify-errors restify-errors-options
Last synced: 3 months ago
JSON representation
🔧 Add custom options to Restify's errors
- Host: GitHub
- URL: https://github.com/simonepri/restify-errors-options
- Owner: simonepri
- License: mit
- Created: 2017-07-30T11:33:44.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-22T20:11:16.000Z (over 7 years ago)
- Last Synced: 2025-03-21T16:07:01.533Z (3 months ago)
- Topics: restify, restify-errors, restify-errors-options
- Language: JavaScript
- Size: 31.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# restify-errors-options
[](https://travis-ci.org/simonepri/restify-errors-options) [](https://codecov.io/gh/simonepri/restify-errors-options) [](https://www.npmjs.com/package/restify-errors-options) [](https://www.npmjs.com/package/restify-errors-options) [](https://david-dm.org/simonepri/restify-errors-options) [](https://david-dm.org/simonepri/restify-errors-options#info=devDependencies)
> 🔧 Add custom options to Restify's errors!
DEPRECATED!!!
## Install
```
$ npm install --save restify-errors-options
```## Usage
```js
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: ''}
```## Plugins
Community packages that implement adds options through this package.
If you want yours listed here open a PR.* [restify-errors-options-errno](https://github.com/simonepri/restify-errors-options-errno): *Add errno to Restify's errors*
## API
### add(optName, [optDefault])
Adds custom options to errors' body.
#### optName
Type: `string`
Name of the option key to add.
#### optDefault
Type: `(number|boolean|string|object)`
Default value for the option.
You can also provide a function, see the next section.#### optDefault(errorCode, errorHttpCode, errorMessage)
Type: `function`
Returns the default value for the option using parameters of the error.
### delete(optName)
Removes previously added custom options..
#### optName
Type: `string`
Name of the option key to remove.
## Authors
* **Simone Primarosa** - [simonepri](https://github.com/simonepri)See also the list of [contributors](https://github.com/simonepri/restify-errors-options/contributors) who participated in this project.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.