New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

koa-2-error-handler

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-2-error-handler

Error handler for Koa 2 application.

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by600%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 05 Feb 2017

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