Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async function apmMiddleware(ctx, next) {
// Skip if apm is disabled
if (!apm.isStarted()) {
debug('Skipped because APM is disabled');
return await next();
}
try {
await next();
} catch (err) {
// Sending error when response is sent
ctx.res.on('finish', () => {
apm.captureError(err);
debug('Sent error to APM server');
});
throw err;
} finally {
// Set custom context data