Merged in feat/SW-1444-destination-page-add-destination-list-component (pull request #1240)
feat/SW-1444 destination page add destination list component * feat(SW-1444): add list component * feat(SW-1444): add subtitle to accordion * feat(SW-1444): refactor component structure * feat(SW-1444): add desktop breakpoint * feat(SW-1444): fix typo * feat(SW-1444): add props * feat(SW-1444): add query * feat(SW-1444): updated query * feat(SW-1444): display data * feat(SW-1444): fix merge hickup * feat(SW-1444): change var name * feat(SW-1444): remove unsued translations * feat(SW-1444): use country as title * feat(SW-1444): sort hotels in query * feat(SW-1444): make responsive * feat(SW-1444): fetch country url * feat(SW-1444): update logging * feat(SW-1444): remove spread Approved-by: Erik Tiekstra
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import { GetCountryPageUrl } from "@/lib/graphql/Query/DestinationOverviewPage/DestinationOverviewPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
|
||||
import { countryPageUrlSchema } from "./output"
|
||||
import {
|
||||
getCountryPageUrlCounter,
|
||||
getCountryPageUrlFailCounter,
|
||||
getCountryPageUrlSuccessCounter,
|
||||
} from "./telemetry"
|
||||
|
||||
import type { GetCountryPageUrlData } from "@/types/trpc/routers/contentstack/destinationOverviewPage"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
export async function getCountryPageUrl(lang: Lang, country: string) {
|
||||
getCountryPageUrlCounter.add(1, { lang, country })
|
||||
console.info(
|
||||
"contentstack.countryPageUrl start",
|
||||
JSON.stringify({ query: { lang, country } })
|
||||
)
|
||||
|
||||
const tag = `${lang}:country_page_url:${country}`
|
||||
const response = await request<GetCountryPageUrlData>(
|
||||
GetCountryPageUrl,
|
||||
{
|
||||
locale: lang,
|
||||
country,
|
||||
},
|
||||
{
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags: [tag],
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
getCountryPageUrlFailCounter.add(1, {
|
||||
lang,
|
||||
country,
|
||||
error_type: "not_found",
|
||||
error: `Country page not found for country: ${country}`,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.countryPageUrl not found error",
|
||||
JSON.stringify({ query: { lang, country } })
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
const validatedCountryPageUrl = countryPageUrlSchema.safeParse(response.data)
|
||||
|
||||
if (!validatedCountryPageUrl.success) {
|
||||
getCountryPageUrlFailCounter.add(1, {
|
||||
lang,
|
||||
country,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedCountryPageUrl.error),
|
||||
})
|
||||
console.error(
|
||||
"contentstack.countryPageUrl validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, country },
|
||||
error: validatedCountryPageUrl.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
getCountryPageUrlSuccessCounter.add(1, { lang, country })
|
||||
console.info(
|
||||
"contentstack.countryPageUrl success",
|
||||
JSON.stringify({ query: { lang, country } })
|
||||
)
|
||||
|
||||
return validatedCountryPageUrl.data
|
||||
}
|
||||
Reference in New Issue
Block a user