Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New attempt to try to catch outlook error #949

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 17 additions & 28 deletions src/hooks/useHandlePageError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function useHandlePageError({
const isIntentionalError = window.location.pathname.includes('debug-sentry')
logger.info(`${humanReadablePageName} Error Page rendered with:`, error)
Sentry.captureException(error, { tags: { domain } })

const message = isIntentionalError
? `Testing Sentry Triggered ${humanReadablePageName} Error Page`
: `${humanReadablePageName} Error Page Displayed`
Expand All @@ -33,39 +34,27 @@ export function useHandlePageError({
}

// we are not sure what causes outlook users to trigger an anti-fingerprint error when accessing
// SWC using the parsed safe link from outlook. This is a fix to prevent errors spikes
// from showing up in Sentry and Mixpanel when new email campaigns are sent out.
// SWC using the parsed safe link from outlook. This fix was added to track the error
// You can find more information about this issue here: https://github.com/Stand-With-Crypto/swc-web/issues/848
const OUTLOOK_BOT_ERROR_MESSAGE = [
'Object Not Found Matching Id:',
'antifingerprint not defined yet',
]
function checkIfErrorIsCausedByOutlook(
error: Error & { digest?: string },
isFromNewsletter: boolean,
) {
if (!isFromNewsletter) return false
const OUTLOOK_BOT_ERROR_MESSAGE = 'Non-Error promise rejection captured with value: '

if (
typeof error !== typeof Error &&
OUTLOOK_BOT_ERROR_MESSAGE.some(errorMsg => error?.toString()?.includes(errorMsg))
) {
return true
}
function checkIfErrorIsCausedByOutlook(error: any, isFromNewsletter: boolean) {
if (!isFromNewsletter) return false

if (OUTLOOK_BOT_ERROR_MESSAGE.some(errorMsg => error?.message?.includes(errorMsg))) return true
if (OUTLOOK_BOT_ERROR_MESSAGE.some(errorMsg => error?.name?.includes(errorMsg))) return true
if (
error?.digest &&
OUTLOOK_BOT_ERROR_MESSAGE.some(errorMsg => error?.digest?.includes(errorMsg))
) {
return true
}
// The conditional logic below was inspired by this suggestion https://github.com/getsentry/sentry-javascript/issues/3440#issuecomment-828834651 as an attempt to try to catch the outlook error
if (
error?.stack &&
OUTLOOK_BOT_ERROR_MESSAGE.some(errorMsg => error?.stack?.includes(errorMsg))
typeof error !== 'undefined' &&
typeof error?.exception !== 'undefined' &&
typeof error?.exception?.values !== 'undefined' &&
error?.exception?.values?.length === 1
) {
return true
const exception = error.exception.values[0]
if (
exception.type === 'UnhandledRejection' &&
exception.value?.includes(OUTLOOK_BOT_ERROR_MESSAGE)
) {
return true
}
}

return false
Expand Down
Loading