egg-error-handler

    2.2.1 • Public • Published

    egg-error-handler

    English|中文

    NPM version build status Test coverage David deps Known Vulnerabilities npm download

    Install

    $ npm i egg-error-handler --save

    Usage

    // {app_root}/config/plugin.js
    exports.errorHandler = {
      enable: true,
      package: 'egg-error-handler',
    };

    Instructions for use

    • The plugin is a middleware plugin that automatically catches exceptions and processes them in the controller layer, prints and logs error logs, and eventually responds to the client with error messages in the following format:
    {
        "code": 400,
        "success": false,
        "message": "NotFoundError: Can't find what you want"
    }
    • By default, all kinds of exceptions will contain an exception's native error hint in the response data after capture, but you can hide the error message for a specific exception (if and only if the runtime environment is prod) Instead of using other text:
    // {app_root}/config/config.default.js
    config.errorHandler2 = {
         // Turn on protection (not enabled by default)
         protection: true,
         // For unpredictable errors, use tips as a client prompt in response (default is 'Internal Server Error')
         tips: 'Internal Server Error',
         // protect against the exception class and all subclasses that inherit the exception class do not work
         ignore: [ClientError]
    };
    • Note: Configured as errorHandler2 instead of errorHandler

    Questions & Suggestions

    Please open an issue here.

    License

    MIT

    Install

    npm i egg-error-handler

    DownloadsWeekly Downloads

    48

    Version

    2.2.1

    License

    MIT

    Unpacked Size

    9.89 kB

    Total Files

    7

    Last publish

    Collaborators

    • iamljw