koa-http-errors

0.4.0 • Public • Published

koa-http-errors

Error response formatter for koa.

NPM version build status Test coverage NPM Monthly Downloads Dependencies License Tips

Usage

var errors = require('koa-http-errors');
 
var app = new koa(); // koa-http-errors^0.4.0 for koa 2.x
app.use(errors());

Options

app.use(errors({
  type: 'text/xml', // optional, to set the Content-type of the response
  engine: 'ejs', // optional, any template engine, see https://www.npmjs.com/package/co-render
  template: './error.ejs', // optional, template file path
  cache: false, // optional, default is true
  render: function *(content) {
    // todo
    // content.msg = error.message
    // content.code = error.code
    // content.env = process.env.NODE_ENV
    // content.engine = options.engine
    // content.template = options.template
    // content.cache = options.cache
    // content.ctx = ctx of koa
    // content.err = err
  } // optional, must be a generator function
}));

Readme

Keywords

Package Sidebar

Install

npm i koa-http-errors

Weekly Downloads

8

Version

0.4.0

License

MIT

Last publish

Collaborators

  • zedgu