From 3d851f214dfde76fb4a856235ea270648d4ae696 Mon Sep 17 00:00:00 2001 From: Favour Ohanekwu Date: Tue, 26 Sep 2023 06:45:55 +0100 Subject: [PATCH] chore: Handle non-error rejections in sentry (#27519) --- app/client/src/utils/AppsmithUtils.tsx | 32 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/app/client/src/utils/AppsmithUtils.tsx b/app/client/src/utils/AppsmithUtils.tsx index 299583b744..f2a3c536dc 100644 --- a/app/client/src/utils/AppsmithUtils.tsx +++ b/app/client/src/utils/AppsmithUtils.tsx @@ -21,21 +21,25 @@ export const initializeAnalyticsAndTrackers = () => { Sentry.init({ ...appsmithConfigs.sentry, beforeSend(event) { - if ( - event.exception && - Array.isArray(event.exception.values) && - event.exception.values[0].value && - event.exception.values[0].type === "ChunkLoadError" - ) { + const exception = extractSentryException(event); + if (exception?.type === "ChunkLoadError") { // Only log ChunkLoadErrors after the 2 retires - if ( - !event.exception.values[0].value.includes( - "failed after 2 retries", - ) - ) { + if (!exception.value?.includes("failed after 2 retries")) { return null; } } + // Handle Non-Error rejections + if (exception?.value?.startsWith("Non-Error")) { + const serializedData: any = event.extra?.__serialized__; + if (!serializedData) return null; // if no data is attached, ignore error + const actualErrorMessage = serializedData.error + ? serializedData.error.message + : serializedData.message; + if (!actualErrorMessage) return null; // If no message is attached, ignore error + // Now modify the original error + exception.value = actualErrorMessage; + event.message = actualErrorMessage; + } return event; }, beforeBreadcrumb(breadcrumb) { @@ -485,3 +489,9 @@ export function getDatatype(value: unknown) { return DataType.UNDEFINED; } } + +function extractSentryException(event: Sentry.Event) { + if (!event.exception) return null; + const value = event.exception.values ? event.exception.values[0] : null; + return value; +}