Merged in chore/add-error-details-for-sentry (pull request #3378)
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
This commit is contained in:
@@ -9,7 +9,7 @@ import { equalsIgnoreCaseAndAccents } from "@scandic-hotels/common/utils/stringE
|
||||
import {
|
||||
gatewayTimeout,
|
||||
httpStatusByErrorCode,
|
||||
notFound,
|
||||
notFoundError,
|
||||
} from "@scandic-hotels/trpc/errors"
|
||||
import {
|
||||
isCityLocation,
|
||||
@@ -36,7 +36,7 @@ export async function GET(
|
||||
)
|
||||
|
||||
if (!country) {
|
||||
throw notFound(`Country "${countryParam.toLowerCase()}" not found`)
|
||||
throw notFoundError(`Country "${countryParam.toLowerCase()}" not found`)
|
||||
}
|
||||
|
||||
const caller = await serverClient()
|
||||
@@ -55,7 +55,7 @@ export async function GET(
|
||||
})
|
||||
|
||||
if (!city) {
|
||||
throw notFound(
|
||||
throw notFoundError(
|
||||
`City "${cityParam.toLowerCase()}" not found in country "${countryParam.toLowerCase()}"`
|
||||
)
|
||||
}
|
||||
@@ -71,7 +71,7 @@ export async function GET(
|
||||
)
|
||||
|
||||
if (hotels.length === 0) {
|
||||
throw notFound(
|
||||
throw notFoundError(
|
||||
`No hotels found in city "${cityParam.toLowerCase()}" and country "${countryParam.toLowerCase()}"`
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { equalsIgnoreCaseAndAccents } from "@scandic-hotels/common/utils/stringE
|
||||
import {
|
||||
gatewayTimeout,
|
||||
httpStatusByErrorCode,
|
||||
notFound,
|
||||
notFoundError,
|
||||
} from "@scandic-hotels/trpc/errors"
|
||||
import {
|
||||
isCityLocation,
|
||||
@@ -36,7 +36,7 @@ export async function GET(
|
||||
)
|
||||
|
||||
if (!country) {
|
||||
throw notFound(`Country "${countryParam.toLowerCase()}" not found`)
|
||||
throw notFoundError(`Country "${countryParam.toLowerCase()}" not found`)
|
||||
}
|
||||
|
||||
const caller = await serverClient()
|
||||
@@ -52,7 +52,7 @@ export async function GET(
|
||||
})
|
||||
|
||||
if (cities.length === 0) {
|
||||
throw notFound(
|
||||
throw notFoundError(
|
||||
`No cities found in country "${countryParam.toLowerCase()}"`
|
||||
)
|
||||
}
|
||||
@@ -71,7 +71,7 @@ export async function GET(
|
||||
)
|
||||
|
||||
if (hotels.length === 0) {
|
||||
throw notFound(
|
||||
throw notFoundError(
|
||||
`No hotels found in country "${countryParam.toLowerCase()}"`
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import * as Sentry from "@sentry/nextjs"
|
||||
import { TRPCError } from "@trpc/server"
|
||||
|
||||
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\//,
|
||||
@@ -26,16 +29,24 @@ async function configureSentry() {
|
||||
release: env.RELEASE_TAG || undefined,
|
||||
beforeSend(event, hint) {
|
||||
const error = hint.originalException
|
||||
|
||||
// Don't send TRPCErrors with client error codes
|
||||
if (error instanceof TRPCError) {
|
||||
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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user