25 lines
708 B
JavaScript
Raw Normal View History

2020-12-14 00:59:12 +01:00
'use strict';
module.exports = async () => {
// Initialize the Sentry service exposed by this plugin
const { sentry } = strapi.plugins.sentry.services;
sentry.init();
// Create a middleware to intercept API errors
strapi.app.use(async (ctx, next) => {
try {
await next();
} catch (error) {
2020-12-14 17:50:19 +01:00
sentry.sendError(error, (scope, sentryInstance) => {
scope.addEventProcessor(event => {
// Parse Koa context to add error metadata
return sentryInstance.Handlers.parseRequest(event, ctx.request);
2020-12-14 00:59:12 +01:00
});
2020-12-14 17:50:19 +01:00
// Manually add Strapi version
scope.setTag('strapi_version', strapi.config.info.strapi);
});
2020-12-14 00:59:12 +01:00
throw error;
}
});
};