🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

koa-airbrake

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-airbrake

Airbrake middleware for Koa

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

koa-airbrake

Airbrake middleware for Koa

Installation

> npm install --save koa-airbrake

Usage

The koa-airbrake middleware intercepts unhandled exceptions in the Koa callstack and reports them to Airbrake. Afterwards, it re-throws the exceptions so that they can continue being processed by the remaining middleware.

const Koa = require('koa');
const app = new Koa();


// Setup your Airbrake client...
const AirbrakeClient = require('airbrake-js');
const airbrake = new AirbrakeClient({  
  projectId: "PROJECT_ID",
  projectKey: 'API_KEY'
});


// Plugin the "koa-airbrake" middleware
const notifyAirbrake = require('koa-airbrake');
app.use(notifyAirbrake(airbrake));


// Let's create a test endpoint that just throws an exception.
app.use(async function(ctx) {
  throw new Error("ka-BOOOOOOOOM!");
});

app.listen(3000);

Gotchas

Exceptions that escape Koa's Callstack

This middleware only handles exceptions that are part of the Koa callstack. For example, consider this code that is using a traditional callback:

app.use(function(ctx) {
  return new Promise(function(resolve, reject) {
    setTimeout(function() {
      throw new Error("Oops!  This exception is never rejected!");
    }, 1000);
  });
});

Since the exception is never passed to the reject callback, it escapes Koa's callstack; therefore it will never be observed by the koa-airbrake middleware. Fortunately, the airbrake library itself provides a handler for these exceptions. Just do this:

// This will intercept any exceptions that escape Koa's callstack.
airbrake.handleExceptions();

Keywords

koa

FAQs

Package last updated on 19 Mar 2019

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