Sentry fix: Always gate reportError to avoid ResizeObserver errors

This commit is contained in:
Ben Gotow 2025-07-15 10:00:25 -05:00
parent 5b08d6f776
commit 9b91e09ff7

View file

@ -152,13 +152,26 @@ export default class AppEnvConstructor {
resourcePath: this.getLoadSettings().resourcePath,
});
// Helper function to check if an error should be ignored and not reported to Sentry
const shouldIgnoreError = (error: any): boolean => {
const errorMessage = `${error}`.toLowerCase();
// ResizeObserver errors happen infrequently but spam Sentry with thousands of reports
if (errorMessage.includes('resizeobserver')) {
return true;
}
// Add more ignored error patterns here as needed
return false;
};
// https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
window.onerror = (message, url, line, column, originalError) => {
if (!originalError && !message) return;
if (!originalError) originalError = new Error(`${message}`);
if (`${originalError}`.toLowerCase().includes('resizeobserver')) {
return; // happens infrequently, but errors a zillion times - too noisy for Sentry
if (shouldIgnoreError(originalError)) {
return;
}
if (!this.inDevMode()) {
@ -169,10 +182,16 @@ export default class AppEnvConstructor {
};
process.on('uncaughtException', error => {
if (shouldIgnoreError(error)) {
return;
}
this.reportError(error);
});
process.on('unhandledRejection', error => {
if (shouldIgnoreError(error)) {
return;
}
this.reportError(error);
});
@ -181,14 +200,23 @@ export default class AppEnvConstructor {
// https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
// In practice, it can have different shapes, so we make our best guess
if (e instanceof Error) {
if (shouldIgnoreError(e)) {
return;
}
this.reportError(e);
return;
}
if (e.reason) {
if (shouldIgnoreError(e.reason)) {
return;
}
this.reportError(e.reason);
return;
}
if ((e as any).detail && (e as any).detail.reason) {
if (shouldIgnoreError((e as any).detail.reason)) {
return;
}
this.reportError((e as any).detail.reason);
return;
}