Socket
Socket
Sign inDemoInstall

egg-onerror

Package Overview
Dependencies
6
Maintainers
6
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    egg-onerror

error handler for egg


Version published
Maintainers
6
Install size
169 kB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 11 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc