mirror of
https://github.com/strapi/strapi.git
synced 2025-08-11 18:27:22 +00:00
28 lines
797 B
JavaScript
28 lines
797 B
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
module.exports = async () => {
|
||
|
// Initialize the Sentry service exposed by this plugin
|
||
|
const { sentry } = strapi.plugins.sentry.services;
|
||
|
sentry.init();
|
||
|
|
||
|
// Only send errors to Sentry if a valid DSN was entered and the plugin isn't disabled
|
||
|
const shouldSendSentryEvents = sentry.isReady;
|
||
|
|
||
|
// Create a middleware to intercept API errors
|
||
|
strapi.app.use(async (ctx, next) => {
|
||
|
try {
|
||
|
await next();
|
||
|
} catch (error) {
|
||
|
if (shouldSendSentryEvents) {
|
||
|
sentry.sendError(error, (scope, sentryInstance) => {
|
||
|
scope.addEventProcessor(event => {
|
||
|
// Parse Koa context to add error metadata
|
||
|
return sentryInstance.Handlers.parseRequest(event, ctx.request);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
throw error;
|
||
|
}
|
||
|
});
|
||
|
};
|