egg-onerror
error handler for egg
Last updated 3 years ago by fengmk2 .
Repository · Bugs · Original npm
$ cnpm install egg-onerror 
SYNC missed versions from official npm registry.

egg-onerror

NPM version build status Test coverage David deps 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 accpet 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 funtion
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

Current Tags

  • 2.1.1                                ...           latest (3 years ago)

3 Versions

  • 2.1.1                                ...           3 years ago
  • 1.6.0                                ...           8 years ago
  • 2.1.0                                ...           7 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (9)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org