Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

egg-onerror

eggjs98.3k2.4.0

error handler for egg

egg, egg-plugin, onerror

readme

egg-onerror

NPM version Node.js CI Test coverage Known Vulnerabilities npm download

Default error handling plugin for egg.

Install

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.
// 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.

License

MIT

Contributors

Contributors

Made with contributors-img.

changelog

Changelog

2.4.0 (2024-10-13)

Features

2.3.1 (2024-10-13)

Bug Fixes

2.3.0 (2024-10-13)

Features

2.2.0 / 2022-12-11

features

2.1.1 / 2022-08-18

fixes

others

2.1.0 / 2018-06-12

features

2.0.0 / 2017-11-13

others

1.6.0 / 2017-11-13

features

others

1.5.0 / 2017-07-20

  • feat: errorPageUrl support function (#21)

1.4.6 / 2017-06-20

  • fix: only output simple error html on unittest (#19)

1.4.5 / 2017-06-20

  • fix: should show 4xx status error html (#18)

1.4.4 / 2017-06-12

  • fix: make error style more good (#17)
  • fix: add error-title's line-height (#16)

1.4.3 / 2017-06-04

  • docs: fix License url (#15)

1.4.2 / 2017-06-01

  • fix: remove error detail on JSON response (#14)

1.4.1 / 2017-06-01

  • fix: add missing files on package.json (#13)

1.4.0 / 2017-05-31

  • feat: better error page on development (#12)

1.3.0 / 2017-01-22

  • feat: use ctx.acceptJSON (#11)

1.2.2 / 2017-01-13

  • fix: should keep support *.json ext to detect response type (#10)

1.2.1 / 2017-01-13

  • fix: add agent.js to package.files (#9)

1.2.0 / 2017-01-13

  • feat: support options.accepts
  • refactor: remove accpetJSON

1.1.0 / 2016-11-09

  • feat: should watch error event on agent (#7)

1.0.0 / 2016-10-21

  • deps: upgrade koa-onerror (#6)
  • fix: make sure ctx always exists (#3)

0.0.3 / 2016-07-16

  • fix: fix this is undefined on arrow function (#1)

0.0.2 / 2016-07-13

  • init code