zero-to-one-onerror

1.0.0 • Public • Published

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.
// config.default.js
// errorPageUrl support funtion
exports.onerror = {
  errorPageUrl: (err, ctx) => ctx.errorPageUrl || '/500',
};

// an accept detect function that mark all request with `x-request-with=XMLHttpRequest` header accepts json.
function accpets(ctx) {
  if (ctx.get('x-request-with') === 'XMLHttpRequest') return 'json';
  return 'html';
}

Questions & Suggestions

Please open an issue here.

License

MIT

/zero-to-one-onerror/

    Package Sidebar

    Install

    npm i zero-to-one-onerror

    Weekly Downloads

    1

    Version

    1.0.0

    License

    ISC

    Last publish

    Collaborators

    • lovelife10000