From 447cbb276d7342257cf271598f09183fa7b82f75 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 24 Sep 2024 16:40:32 +0800 Subject: [PATCH] chore: filter sentry error Signed-off-by: Innei --- apps/renderer/src/configs.ts | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/apps/renderer/src/configs.ts b/apps/renderer/src/configs.ts index 8c2e12064..81cf6e853 100644 --- a/apps/renderer/src/configs.ts +++ b/apps/renderer/src/configs.ts @@ -4,6 +4,18 @@ import { FetchError } from "ofetch" import { CustomSafeError } from "./components/errors/helper" +const ERROR_PATTERNS = [ + /Network Error/i, + /Fetch Error/i, + /XHR Error/i, + /adsbygoogle/i, + /Failed to fetch/i, + "fetch failed", + "Unable to open cursor", + "Document is not focused.", + "HTTP Client Error", +] + export const SentryConfig: BrowserOptions = { // Performance Monitoring tracesSampleRate: 1, // Capture 100% of the transactions @@ -16,18 +28,14 @@ export const SentryConfig: BrowserOptions = { beforeSend(event, hint) { const error = hint.originalException - if ( - error instanceof Error && - (/Network Error/i.test(error.message) || - /Fetch Error/i.test(error.message) || - /XHR Error/i.test(error.message) || - /adsbygoogle/i.test(error.message) || - /Failed to fetch/i.test(error.message) || - error.message.includes("fetch failed") || - error.message.includes("Unable to open cursor") || - error.message.includes("Document is not focused.")) - ) { - return null + if (error instanceof Error) { + const isIgnoredError = ERROR_PATTERNS.some((pattern) => + pattern instanceof RegExp ? pattern.test(error.message) : error.message.includes(pattern), + ) + + if (isIgnoredError) { + return null + } } const isPassthroughError = [CustomSafeError, FetchError].some((errorType) => {