Package Exports
- koa-error
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-error) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
koa-error
Error response middleware for koa supporting:
- text
- json
- html
Installation
$ npm install koa-errorOptions
templatepath to template written with your template engineenginetemplate engine name passed to consolidatecachecached compiled functions, default:NODE_ENV != 'development'envforce a NODE_ENV, default:developmentacceptsmimetypes 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:
envctxrequestresponseerrorstackstatuscode
Here are some examples:
Pug (formerly jade)
app.use(error({
engine: 'pug',
template: __dirname + '/error.pug'
}));doctype html
html
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= stackNunjucks
app.use(error({
engine: 'nunjucks',
template: __dirname + '/error.njk'
}));<!DOCTYPE html>
<html>
<head>
<title>Error - {{status}}</title>
</head>
<body>
<div id="error">
<h1>Error</h1>
<p>Looks like something broke!</p>
{% if env == 'development' %}
<h2>Message:</h2>
<pre>
<code>
{{error}}
</code>
</pre>
<h2>Stack:</h2>
<pre>
<code>
{{stack}}
</code>
</pre>
{% endif %}
</div>
</body>
</html>License
MIT