Add error patterns to ignore in Sentry events

This commit is contained in:
Enno Gelhaus 2025-09-20 10:50:17 +02:00 committed by GitHub
parent ec69b689c5
commit 8078814211
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 9 deletions

View File

@ -5,6 +5,15 @@ export const initializeSentryBasic = (environment: string, dsn: string, extensio
return;
}
const ignorePatterns = [
/^Failed to fetch$/,
/^Failed to fetch .*/i,
/^Load failed$/i,
/^Load failed .*/i,
/^NetworkError when attempting to fetch resource\.$/i,
/^NetworkError when attempting to fetch resource\. .*/i,
];
try {
Sentry.init({
initialScope: {
@ -27,24 +36,25 @@ export const initializeSentryBasic = (environment: string, dsn: string, extensio
debug: environment === 'development',
tracesSampleRate: environment === 'development' ? 1.0 : 0.3,
// Filtert Events und zeigt das User-Feedback-Modal an
beforeSend(event, hint) {
if (event.exception && event.exception.values) {
for (const exception of event.exception.values) {
// Filtert "Failed to fetch" Fehler heraus
if (exception.value && /Failed to fetch/.test(exception.value)) {
return null; // Verwirft den Event
if (exception.value) {
for (const pattern of ignorePatterns) {
if (pattern.test(exception.value)) {
return null; // Ignore the event
}
}
}
}
}
// Wenn der Event eine Ausnahme ist und nicht gefiltert wurde,
// wird das User-Feedback-Modal angezeigt
// Show user feedback modal if not filtered
if (event.exception && event.event_id) {
Sentry.showReportDialog({ eventId: event.event_id });
}
return event; // Sendet den Event an Sentry
return event; // Send the event to Sentry
},
});
} catch (err) {}