chore: Handle non-error rejections in sentry (#27519)

This commit is contained in:
Favour Ohanekwu 2023-09-26 06:45:55 +01:00 committed by GitHub
parent 6f7dd7254b
commit 3d851f214d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}