This package has been deprecated

    Author message:

    This package is unmaintained and may not works for version of restify > 5.0.1 and restify-errors > 4.3.0. Please see https://github.com/restify/errors#customizing-errors

    restify-errors-options

    0.3.2 • Public • Published

    restify-errors-options

    Travis CI Codecov npm npm version npm dependencies npm dev dependencies

    🔧 Add custom options to Restify's errors!


    DEPRECATED!!!


    Install

    $ npm install --save restify-errors-options
    

    Usage

    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.

    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

    See also the list of contributors who participated in this project.

    License

    This project is licensed under the MIT License - see the LICENSE file for details.

    Install

    npm i restify-errors-options

    DownloadsWeekly Downloads

    23

    Version

    0.3.2

    License

    MIT

    Unpacked Size

    10.4 kB

    Total Files

    4

    Last publish

    Collaborators

    • simonepri