Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eggjs/egg-onerror
error handler for egg
https://github.com/eggjs/egg-onerror
egg-plugin
Last synced: about 1 month ago
JSON representation
error handler for egg
- Host: GitHub
- URL: https://github.com/eggjs/egg-onerror
- Owner: eggjs
- License: mit
- Created: 2016-07-13T02:28:43.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-13T06:31:50.000Z (2 months ago)
- Last Synced: 2024-10-29T21:05:53.800Z (about 1 month ago)
- Topics: egg-plugin
- Language: Mustache
- Homepage:
- Size: 128 KB
- Stars: 57
- Watchers: 7
- Forks: 14
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
- awesome-egg - egg-onerror - 统一异常处理。 ![](https://img.shields.io/github/stars/eggjs/egg-onerror.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/egg-onerror.svg?style=flat-square) (仓库 / [内置插件](https://eggjs.org/zh-cn/basics/plugin.html#%E6%8F%92%E4%BB%B6%E5%88%97%E8%A1%A8))
README
# egg-onerror
[![NPM version][npm-image]][npm-url]
[![Node.js CI](https://github.com/eggjs/egg-onerror/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-onerror/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url][npm-image]: https://img.shields.io/npm/v/egg-onerror.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-onerror
[codecov-image]: https://codecov.io/github/eggjs/egg-onerror/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/eggjs/egg-onerror?branch=master
[snyk-image]: https://snyk.io/test/npm/egg-onerror/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-onerror
[download-image]: https://img.shields.io/npm/dm/egg-onerror.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-onerrorDefault error handling plugin for egg.
## Install
```bash
npm i egg-onerror
```## Usage
`egg-onerror` is on by default in egg. But you still can configure its properties to fits your scenarios.
- `errorPageUrl: String or Function` - If user request html pages in production environment and unexpected error happened, it will redirect user to `errorPageUrl`.
- `accepts: Function` - detect user's request accept `json` or `html`.
- `all: Function` - customize error handler, if `all` present, negotiation will be ignored.
- `html: Function` - customize html error handler.
- `text: Function` - customize text error handler.
- `json: Function` - customize json error handler.
- `jsonp: Function` - customize jsonp error handler.```js
// config.default.js
// errorPageUrl support function
exports.onerror = {
errorPageUrl: (err, ctx) => ctx.errorPageUrl || '/500',
};// an accept detect function that mark all request with `x-requested-with=XMLHttpRequest` header accepts json.
function accepts(ctx) {
if (ctx.get('x-requested-with') === 'XMLHttpRequest') return 'json';
return 'html';
}
```## Questions & Suggestions
Please open an issue [here](https://github.com/eggjs/egg/issues).
## License
[MIT](https://github.com/eggjs/egg-onerror/blob/master/LICENSE)
## Contributors
[![Contributors](https://contrib.rocks/image?repo=eggjs/egg-onerror)](https://github.com/eggjs/egg-onerror/graphs/contributors)
Made with [contributors-img](https://contrib.rocks).