koa-error
Error response middleware for koa supporting:
- text
- json
- html
Installation
$ npm install koa-error
Options
template
path to template written with your template engineengine
template engine name passed to consolidatecache
cached compiled functions, default:NODE_ENV != 'development'
env
force a NODE_ENV, default:development
accepts
mimetypes passed to ctx.accepts, default:[ 'html', 'text', 'json' ]
Custom templates
By using the template
option you can override the bland default template,
with the following available local variables:
env
ctx
request
response
error
stack
status
code
Here are some examples:
Pug (formerly jade)
app;
doctype htmlhtml head title= 'Error - ' + status body #error h1 Error p Looks like something broke! if env == 'development' h2 Message: pre: code= error h2 Stack: pre: code= stack
Nunjucks
app;
Error - {{status}} Error Looks like something broke! {% if env == 'development' %} Message: {{error}} Stack: {{stack}} {% endif %}
License
MIT