New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@eggjs/onerror

Package Overview
Dependencies
Maintainers
10
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eggjs/onerror

error handler for egg

Source
npmnpm
Version
4.0.2
Version published
Weekly downloads
0
Maintainers
10
Weekly downloads
 
Created
Source

@eggjs/onerror

NPM version Known Vulnerabilities npm download Node.js Version PRs Welcome CodeRabbit Pull Request Reviews

Default error handling plugin for egg.

Usage

onerror plugin is enabled 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.
  • js: Function - customize JSONP error handler.
// config/config.default.ts
import { defineConfig } from 'egg';

export default defineConfig({
  onerror: {
    // errorPageUrl support function
    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.

Keywords

egg

FAQs

Package last updated on 06 Oct 2026

Related posts