# error **Repository Path**: mirrors_koajs/error ## Basic Information - **Project Name**: error - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-09 - **Last Updated**: 2026-05-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # koa-error Error response middleware for koa supporting: - [x] text - [x] json - [x] html ## Installation ```bash # npm $ npm install koa-error # yarn $ yarn add koa-error ``` ## Options - `template` path to template written with your template engine, default: `./error.html` - `engine` template engine name passed to [consolidate](https://github.com/ladjs/consolidate), default: `lodash` - `cache` cached compiled functions, default: `NODE_ENV != 'development'` - `env` force a NODE_ENV, default: `development` - `accepts` mimetypes passed to [ctx.accepts](https://github.com/koajs/koa/blob/master/docs/api/request.md#requestacceptstypes), 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) ```js app.use( error({ engine: "pug", template: __dirname + "/error.pug", }) ); ``` ```jade 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= stack ``` ### Nunjucks ```js app.use( error({ engine: "nunjucks", template: __dirname + "/error.njk", }) ); ``` ```html
Looks like something broke!
{% if env == 'development' %}
{{error}}
{{stack}}
{% endif %}
{{ request | stringify }}
{# use filters here #} ``` `tpl/com.html`: ```html ``` ## License [MIT](LICENSE)