Include more details when throwing errors for debugging in Sentry * WIP throw errors with more details for debugging in Sentry * Fix throwing response-data * Clearer message when a response fails * Add message to errors * better typings * . * Try to send profileID and membershipNumber to Sentry when we fail to parse the apiResponse * rename notFound -> notFoundError * Merge branch 'master' of bitbucket.org:scandic-swap/web into chore/add-error-details-for-sentry Approved-by: Linus Flood
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import * as Sentry from "@sentry/nextjs"
|
|
|
|
import { isCustomCause } from "@scandic-hotels/trpc/errors"
|
|
|
|
import { env } from "./env/server"
|
|
|
|
import type { TRPCError } from "@trpc/server"
|
|
|
|
export const denyUrls: (string | RegExp)[] = [
|
|
// Ignore preview urls
|
|
/\/.{2}\/preview\//,
|
|
]
|
|
|
|
export async function register() {
|
|
await configureSentry()
|
|
}
|
|
|
|
export const onRequestError = Sentry.captureRequestError
|
|
|
|
async function configureSentry() {
|
|
Sentry.init({
|
|
dsn: "https://fe39c070b4154e2f9cc35f0e5de0aedb@o4508102497206272.ingest.de.sentry.io/4508102500286544",
|
|
environment: env.SENTRY_ENVIRONMENT,
|
|
enabled: env.SENTRY_ENVIRONMENT !== "development",
|
|
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 (isTRPCError(error)) {
|
|
const clientErrorCodes = ["CONFLICT", "NOT_FOUND", "UNAUTHORIZED"]
|
|
if (clientErrorCodes.includes(error.code)) {
|
|
return null // Don't send to Sentry
|
|
}
|
|
|
|
if (isCustomCause(error.cause)) {
|
|
event.contexts = event.contexts || {}
|
|
event.contexts.errorDetails = { data: error.cause.errorDetails }
|
|
}
|
|
}
|
|
|
|
return event
|
|
},
|
|
})
|
|
}
|
|
|
|
function isTRPCError(error: unknown): error is TRPCError {
|
|
return error instanceof Error && error.name === "TRPCError"
|
|
}
|