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
148 lines
4.0 KiB
TypeScript
148 lines
4.0 KiB
TypeScript
import { createCounter } from "@scandic-hotels/common/telemetry"
|
|
|
|
import { router } from "../../.."
|
|
import { notFoundError } from "../../../errors"
|
|
import {
|
|
GetDestinationCityPage,
|
|
GetDestinationCityPageRefs,
|
|
} from "../../../graphql/Query/DestinationCityPage/DestinationCityPage.graphql"
|
|
import { request } from "../../../graphql/request"
|
|
import { contentStackUidWithServiceProcedure } from "../../../procedures"
|
|
import { generateRefsResponseTag } from "../../../utils/generateTag"
|
|
import { getCityByCityIdentifier } from "../../hotels/services/getCityByCityIdentifier"
|
|
import {
|
|
destinationCityPageRefsSchema,
|
|
destinationCityPageSchema,
|
|
} from "./output"
|
|
import { generatePageTags } from "./utils"
|
|
|
|
import type {
|
|
GetDestinationCityPageData,
|
|
GetDestinationCityPageRefsSchema,
|
|
} from "../../../types/destinationCityPage"
|
|
import type { TrackingPageData } from "../../types"
|
|
|
|
export const destinationCityPageQueryRouter = router({
|
|
get: contentStackUidWithServiceProcedure.query(async ({ ctx }) => {
|
|
const { lang, uid, serviceToken } = ctx
|
|
|
|
const getDestinationCityPageRefsCounter = createCounter(
|
|
"trpc.contentstack.destinationCityPage.get.refs"
|
|
)
|
|
const metricsGetDestinationCityPageRefs =
|
|
getDestinationCityPageRefsCounter.init({ lang, uid })
|
|
|
|
metricsGetDestinationCityPageRefs.start()
|
|
|
|
const variables = { locale: lang, uid }
|
|
const refsResponse = await request<GetDestinationCityPageRefsSchema>(
|
|
GetDestinationCityPageRefs,
|
|
variables,
|
|
{
|
|
key: generateRefsResponseTag(lang, uid),
|
|
ttl: "max",
|
|
}
|
|
)
|
|
|
|
if (!refsResponse.data) {
|
|
metricsGetDestinationCityPageRefs.noDataError()
|
|
throw notFoundError({
|
|
message: "GetDestinationCityPageRefs returned no data",
|
|
errorDetails: variables,
|
|
})
|
|
}
|
|
|
|
const validatedRefsData = destinationCityPageRefsSchema.safeParse(
|
|
refsResponse.data
|
|
)
|
|
if (!validatedRefsData.success) {
|
|
metricsGetDestinationCityPageRefs.validationError(validatedRefsData.error)
|
|
return null
|
|
}
|
|
|
|
metricsGetDestinationCityPageRefs.success()
|
|
|
|
const tags = generatePageTags(validatedRefsData.data, lang)
|
|
|
|
const getDestinationCityPageCounter = createCounter(
|
|
"trpc.contentstack.destinationCityPage.get"
|
|
)
|
|
const metricsGetDestinationCityPage = getDestinationCityPageCounter.init({
|
|
lang,
|
|
uid,
|
|
})
|
|
|
|
metricsGetDestinationCityPage.start()
|
|
|
|
const response = await request<GetDestinationCityPageData>(
|
|
GetDestinationCityPage,
|
|
variables,
|
|
{
|
|
key: tags,
|
|
ttl: "max",
|
|
}
|
|
)
|
|
if (!response.data) {
|
|
metricsGetDestinationCityPage.noDataError()
|
|
|
|
throw notFoundError({
|
|
message: "GetDestinationCityPage returned no data",
|
|
errorDetails: variables,
|
|
})
|
|
}
|
|
|
|
const validatedResponse = destinationCityPageSchema.safeParse(response.data)
|
|
|
|
if (!validatedResponse.success) {
|
|
metricsGetDestinationCityPage.validationError(validatedResponse.error)
|
|
return null
|
|
}
|
|
|
|
const destinationCityPage = validatedResponse.data.destination_city_page
|
|
const cityIdentifier = destinationCityPage.destination_settings.city
|
|
if (!cityIdentifier) {
|
|
return null
|
|
}
|
|
|
|
const city = await getCityByCityIdentifier({
|
|
cityIdentifier,
|
|
lang,
|
|
serviceToken,
|
|
})
|
|
|
|
if (!city) {
|
|
metricsGetDestinationCityPage.dataError(
|
|
`Failed to get city data for ${cityIdentifier}`,
|
|
{
|
|
cityIdentifier,
|
|
}
|
|
)
|
|
return null
|
|
}
|
|
|
|
metricsGetDestinationCityPage.success()
|
|
|
|
const system = destinationCityPage.system
|
|
const pageName = `destinations|${city.country}|${city.name}`
|
|
|
|
const tracking: TrackingPageData = {
|
|
pageId: system.uid,
|
|
domainLanguage: system.locale,
|
|
publishDate: system.updated_at,
|
|
createDate: system.created_at,
|
|
channel: "hotels",
|
|
pageType: "citypage",
|
|
pageName,
|
|
siteSections: pageName,
|
|
siteVersion: "new-web",
|
|
}
|
|
|
|
return {
|
|
destinationCityPage,
|
|
cityIdentifier,
|
|
city,
|
|
tracking,
|
|
}
|
|
}),
|
|
})
|