JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 27628
  • Score
    100M100P100Q153974F
  • License MIT

koa error handler, hack ctx.onerror

Package Exports

  • koa-onerror

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (koa-onerror) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

koa-onerror

Build Status

an error handler for koa, hack ctx.onerror

different with koa-error:

  • we can not just use try catch to handle all errors, steams' and events' errors are directly handle by ctx.onerror, so if we want to handle all errors in one place, the only way i can see is to hack ctx.onerror.
  • it is more customizable.

install

npm install koa-onerror

Usage

var fs = require('fs');
var koa = require('koa');
var onerror = require('koa-onerror');
var app = koa();

onerror(app);

app.use(function *(){
  // foo();
  this.body = fs.createReadStream('not exist');
});

Options

error(app, options);
  • all: if options.all exist, ignore negotiation
  • text: text error handler
  • json: json error handler
  • html: html error handler
  • template: default html error handler template path

License

MIT