Socket
Socket
Sign inDemoInstall

koa-2-error-handler

Package Overview
Dependencies
1
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    koa-2-error-handler

Error handler for Koa 2 application.


Version published
Weekly downloads
6
increased by500%
Maintainers
1
Install size
33.6 kB
Created
Weekly downloads
 

Readme

Source

Koa.js 2 error handler

Build Status Coverage Status

Description

Error handler for Koa 2 application

Installation

npm i -S koa-2-error-handler

Documentation

Error handle middleware

Error handle middleware should be the first app.use middleware

const Koa = require('koa');
const app = new Koa();
const error = require('koa-2-error-handler').error;
app.use(error());

Or we can update response error message:

app.use(error((err, ctx) => {
    ctx.body = {
        message: err.message
    };
    console.error(err);
}));

Server event listeners

We can use node.js http server and process server events:

app.js:

const Koa = require('koa');
const app = module.exports = new Koa();

bin/www

#!/usr/bin/env node

/**
 * Module dependencies.
 */
const http = require('http');
const errorHandler = require('koa-2-error-handler');
const app = require('../app');

/**
 * Create HTTP server.
 */
const server = http.createServer(app.callback());

/**
 * Listen on provided port, on all network interfaces.
 */
server.listen(errorHandler.helper(process.env.PORT || '3000'));

/**
 * Handling  listening and error events
 */
errorHandler.server(server, console.info, console.error);

package.json:

"scripts": {
    "start": "node --harmony ./bin/www",
    ...
}

Packages

Modules:

Testing:

Keywords

FAQs

Last updated on 05 Feb 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc