
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
koa-airbrake
Advanced tools
Airbrake middleware for Koa
> npm install --save koa-airbrake
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);
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();
FAQs
Airbrake middleware for Koa
We found that koa-airbrake demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.