Socket
Socket
Sign inDemoInstall

koa-error

Package Overview
Dependencies
Maintainers
6
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-error

Error reponses (text, json, html) for koa


Version published
Maintainers
6
Created
Source

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 engine
  • engine template engine name passed to consolidate
  • cache 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.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= stack

Nunjucks

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

Keywords

FAQs

Package last updated on 11 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc