egg-onerror

    2.1.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.
    • 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

    Install

    npm i egg-onerror

    DownloadsWeekly Downloads

    27,973

    Version

    2.1.0

    License

    none

    Unpacked Size

    53.5 kB

    Total Files

    10

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar