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
70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
import { cache } from "react"
|
|
|
|
import { createCounter } from "@scandic-hotels/common/telemetry"
|
|
|
|
import { router } from "../../.."
|
|
import { notFoundError } from "../../../errors"
|
|
import { GetAllSasTierComparison } from "../../../graphql/Query/SASTierComparison.graphql"
|
|
import { request } from "../../../graphql/request"
|
|
import { contentstackBaseProcedure } from "../../../procedures"
|
|
import { validateSasTierComparisonSchema } from "./output"
|
|
|
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
|
import type { z } from "zod"
|
|
|
|
type SasTierComparisonResponse = z.input<typeof validateSasTierComparisonSchema>
|
|
|
|
export const getSasTierComparison = cache(async (lang: Lang) => {
|
|
const getSasTierComparisonCounter = createCounter(
|
|
"trpc.contentstack.partner.getSasTierComparison"
|
|
)
|
|
const metricsGetSasTierComparison = getSasTierComparisonCounter.init({
|
|
lang,
|
|
})
|
|
|
|
metricsGetSasTierComparison.start()
|
|
|
|
const tag = `${lang}:sas_tier_comparison`
|
|
const sasTierComparisonConfigResponse =
|
|
await request<SasTierComparisonResponse>(
|
|
GetAllSasTierComparison,
|
|
{ lang },
|
|
{
|
|
key: tag,
|
|
ttl: "max",
|
|
}
|
|
)
|
|
|
|
if (!sasTierComparisonConfigResponse.data) {
|
|
metricsGetSasTierComparison.noDataError()
|
|
|
|
throw notFoundError({
|
|
message: "GetAllSasTierComparison returned no data",
|
|
errorDetails: { lang },
|
|
})
|
|
}
|
|
|
|
const validatedSasTierComparison = validateSasTierComparisonSchema.safeParse(
|
|
sasTierComparisonConfigResponse.data
|
|
)
|
|
|
|
if (!validatedSasTierComparison.success) {
|
|
metricsGetSasTierComparison.validationError(
|
|
validatedSasTierComparison.error
|
|
)
|
|
return null
|
|
}
|
|
|
|
metricsGetSasTierComparison.success()
|
|
|
|
return validatedSasTierComparison.data
|
|
})
|
|
|
|
export const partnerQueryRouter = router({
|
|
getSasTierComparison: contentstackBaseProcedure.query(async function ({
|
|
ctx,
|
|
}) {
|
|
return getSasTierComparison(ctx.lang)
|
|
}),
|
|
})
|