egg-error-handler
v2.2.1
Published
Error capture on controller handler plugin for egg
Downloads
161
Maintainers
Readme
egg-error-handler
English|中文
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 oferrorHandler
Questions & Suggestions
Please open an issue here.