Merged in fix/dont-send-expected-error-types-to-sentry (pull request #3358)

fix: don't send expected errors to Sentry

* fix: don't send expected errors to Sentry

* remove BAD_REQUEST from ignore-list for TRPC errors due to BAD_REQUEST being used improperly


Approved-by: Anton Gunnarsson
This commit is contained in:
Joakim Jäderberg
2025-12-17 12:46:07 +00:00
parent ac53f128af
commit 79f1c516c0
2 changed files with 29 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import * as Sentry from "@sentry/nextjs"
import { TRPCError } from "@trpc/server"
import { env } from "./env/server"
@@ -21,6 +22,20 @@ async function configureSentry() {
tracesSampleRate: env.SENTRY_SERVER_SAMPLERATE,
denyUrls: denyUrls,
enableLogs: true,
enableMetrics: true,
release: env.RELEASE_TAG || undefined,
beforeSend(event, hint) {
const error = hint.originalException
// Don't send TRPCErrors with client error codes
if (error instanceof TRPCError) {
const clientErrorCodes = ["CONFLICT", "NOT_FOUND", "UNAUTHORIZED"]
if (clientErrorCodes.includes(error.code)) {
return null // Don't send to Sentry
}
}
return event
},
})
}

View File

@@ -1,4 +1,5 @@
import * as Sentry from "@sentry/nextjs"
import { TRPCError } from "@trpc/server"
import { env } from "./env/server"
@@ -23,5 +24,18 @@ async function configureSentry() {
enableLogs: true,
enableMetrics: true,
release: env.RELEASE_TAG || undefined,
beforeSend(event, hint) {
const error = hint.originalException
// Don't send TRPCErrors with client error codes
if (error instanceof TRPCError) {
const clientErrorCodes = ["CONFLICT", "NOT_FOUND", "UNAUTHORIZED"]
if (clientErrorCodes.includes(error.code)) {
return null // Don't send to Sentry
}
}
return event
},
})
}