2.2.0 • Published 1 year ago

egg-onerror v2.2.0

Weekly downloads
22,889
License
-
Repository
github
Last release
1 year ago

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

2.2.0

1 year ago

2.1.1

2 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.6.0

6 years ago

1.5.0

7 years ago

1.4.6

7 years ago

1.4.5

7 years ago

1.4.4

7 years ago

1.4.3

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.1.0

7 years ago

1.0.0

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago