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 = ;const app = ; // Setup your Airbrake client...const AirbrakeClient = ;const airbrake = projectId: "PROJECT_ID" projectKey: 'API_KEY'; // Plugin the "koa-airbrake" middlewareconst notifyAirbrake = ;app; // Let's create a test endpoint that just throws an exception.app; app;
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;
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;