Files
web/packages/trpc/lib/routers/contentstack/profilingConsent/query.ts
Joakim Jäderberg 99537b13e8 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
2026-01-12 09:01:44 +00:00

63 lines
1.8 KiB
TypeScript

import { createCounter } from "@scandic-hotels/common/telemetry"
import { router } from "../../.."
import { notFoundError } from "../../../errors"
import { GetProfilingConsent } from "../../../graphql/Query/ProfilingConsent.graphql"
import { request } from "../../../graphql/request"
import { contentstackBaseProcedure } from "../../../procedures"
import { langInput } from "../../../utils"
import { profilingConsentSchema } from "./output"
import type { GetProfilingConsentData } from "../../../types/profilingConsent"
export const profilingConsentQueryRouter = router({
get: contentstackBaseProcedure
.input(langInput.optional())
.query(async ({ input, ctx }) => {
const lang = input?.lang ?? ctx.lang
const tag = `${lang}:profiling_consent`
const getProfilingConsentCounter = createCounter(
"trpc.contentstack.profilingConsent.get"
)
const metricsGetProfilingConsent = getProfilingConsentCounter.init({
lang,
})
metricsGetProfilingConsent.start()
const response = await request<GetProfilingConsentData>(
GetProfilingConsent,
{
locale: lang,
},
{
key: tag,
ttl: "max",
}
)
if (!response.data) {
metricsGetProfilingConsent.noDataError()
throw notFoundError({
message: "GetProfilingConsent returned no data",
errorDetails: { lang },
})
}
const validatedResponse = profilingConsentSchema.safeParse(response.data)
if (!validatedResponse.success) {
metricsGetProfilingConsent.validationError(validatedResponse.error)
return null
}
const profiling_consent = validatedResponse.data
metricsGetProfilingConsent.success()
return {
profiling_consent,
}
}),
})