fix: add improved logging for contentstack requests
This commit is contained in:
@@ -67,7 +67,7 @@ export const accountPageQueryRouter = router({
|
||||
generateTags(lang, connections),
|
||||
generateTag(lang, validatedAccountPageRefs.data.account_page.system.uid),
|
||||
].flat()
|
||||
|
||||
console.info("contentstack.accountPage start ", { lang, uid })
|
||||
const response = await request<AccountPageDataRaw>(
|
||||
GetAccountPage,
|
||||
{
|
||||
@@ -78,6 +78,7 @@ export const accountPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
console.error("contentstack.accountPage not found error", { lang, uid })
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
@@ -86,11 +87,13 @@ export const accountPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedAccountPage.success) {
|
||||
console.error(`Failed to validate Account Page - (uid: ${uid})`)
|
||||
console.error(validatedAccountPage.error)
|
||||
console.error(
|
||||
"contentstack.accountPage validation error",
|
||||
JSON.stringify(validatedAccountPage.error)
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
console.info("contentstack.accountPage success ", { lang, uid })
|
||||
// TODO: Make returned data nicer
|
||||
const content = validatedAccountPage.data.account_page.content.map(
|
||||
(block) => {
|
||||
|
||||
@@ -33,12 +33,17 @@ import {
|
||||
export const baseQueryRouter = router({
|
||||
contact: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||
const { lang } = ctx
|
||||
|
||||
console.info("contentstack.config start ", JSON.stringify({ lang }))
|
||||
const response = await request<ContactConfigData>(GetContactConfig, {
|
||||
locale: lang,
|
||||
})
|
||||
|
||||
if (!response.data) {
|
||||
console.error(
|
||||
"contentstack.config not found error ",
|
||||
JSON.stringify({ lang }),
|
||||
JSON.stringify(response)
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
@@ -48,21 +53,33 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!validatedContactConfigConfig.success) {
|
||||
console.error(
|
||||
`Failed to validate Contact Config Data - (lang: ${ctx.lang})`
|
||||
"contentstack.config validation error ",
|
||||
JSON.stringify({ lang }),
|
||||
JSON.stringify(validatedContactConfigConfig.error)
|
||||
)
|
||||
console.error(validatedContactConfigConfig.error)
|
||||
return null
|
||||
}
|
||||
|
||||
console.info("contentstack.config success ", JSON.stringify({ lang }))
|
||||
return validatedContactConfigConfig.data.all_contact_config.items[0]
|
||||
}),
|
||||
header: contentstackBaseProcedure
|
||||
.input(langInput)
|
||||
.query(async ({ input }) => {
|
||||
console.info(
|
||||
"contentstack.header.ref start ",
|
||||
JSON.stringify({ lang: input.lang })
|
||||
)
|
||||
const responseRef = await request<HeaderRefDataRaw>(GetCurrentHeaderRef, {
|
||||
locale: input.lang,
|
||||
})
|
||||
console.info(
|
||||
"contentstack.header. start ",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
})
|
||||
)
|
||||
|
||||
// There's currently no error handling/validation for the responseRef, should it be added?
|
||||
const response = await request<HeaderDataRaw>(
|
||||
GetCurrentHeader,
|
||||
{ locale: input.lang },
|
||||
@@ -77,6 +94,13 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
console.error(
|
||||
"contentstack.header not found error ",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
}),
|
||||
JSON.stringify(response)
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
@@ -85,11 +109,21 @@ export const baseQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!validatedHeaderConfig.success) {
|
||||
console.error(`Failed to validate Header - (lang: ${input.lang})`)
|
||||
console.error(validatedHeaderConfig.error)
|
||||
console.error(
|
||||
"contentstack.header validation error",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
}),
|
||||
JSON.stringify(validatedHeaderConfig.error)
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
console.info(
|
||||
"contentstack.header success ",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
})
|
||||
)
|
||||
const logo =
|
||||
validatedHeaderConfig.data.all_current_header.items[0].logoConnection
|
||||
.edges?.[0]?.node
|
||||
@@ -102,10 +136,17 @@ export const baseQueryRouter = router({
|
||||
footer: contentstackBaseProcedure
|
||||
.input(langInput)
|
||||
.query(async ({ input }) => {
|
||||
console.info("contentstack.footer.ref start ", { lang: input.lang })
|
||||
const responseRef = await request<FooterRefDataRaw>(GetCurrentFooterRef, {
|
||||
locale: input.lang,
|
||||
})
|
||||
|
||||
// There's currently no error handling/validation for the responseRef, should it be added?
|
||||
console.info(
|
||||
"contentstack.footer start ",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
})
|
||||
)
|
||||
const response = await request<FooterDataRaw>(
|
||||
GetCurrentFooter,
|
||||
{
|
||||
@@ -121,16 +162,30 @@ export const baseQueryRouter = router({
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
console.error(
|
||||
"contentstack.footer not found error ",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
}),
|
||||
JSON.stringify(response)
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
const validatedFooterConfig = validateFooterConfigSchema.safeParse(
|
||||
response.data
|
||||
)
|
||||
|
||||
if (!validatedFooterConfig.success) {
|
||||
console.error(`Failed to validate Footer - (lang: ${input.lang})`)
|
||||
console.error(validatedFooterConfig.error)
|
||||
console.error(
|
||||
"contentstack.footer validation error",
|
||||
JSON.stringify({ lang: input.lang }),
|
||||
JSON.stringify(validatedFooterConfig.error)
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
console.info("contentstack.footer success ", { lang: input.lang })
|
||||
return validatedFooterConfig.data.all_current_footer.items[0]
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -8,11 +8,16 @@ import { HotelPage, HotelPageDataRaw, validateHotelPageSchema } from "./output"
|
||||
export const hotelPageQueryRouter = router({
|
||||
get: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
console.info("contentstack.hotelPage start ", JSON.stringify({ lang, uid }))
|
||||
const response = await request<HotelPageDataRaw>(GetHotelPage, {
|
||||
locale: lang,
|
||||
uid,
|
||||
})
|
||||
if (!response.data) {
|
||||
console.error(
|
||||
"contentstack.hotelPage not found error",
|
||||
JSON.stringify({ lang, uid })
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
@@ -20,9 +25,10 @@ export const hotelPageQueryRouter = router({
|
||||
|
||||
if (!validatedHotelPage.success) {
|
||||
console.error(
|
||||
`Failed to validate Hotel Page - (uid: ${uid}, lang: ${lang})`
|
||||
"contentstack.hotelPage validation error",
|
||||
JSON.stringify({ lang, uid }),
|
||||
JSON.stringify(validatedHotelPage.error)
|
||||
)
|
||||
console.error(validatedHotelPage.error)
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +131,14 @@ export const languageSwitcherQueryRouter = router({
|
||||
if (!ctx.uid || !ctx.lang) {
|
||||
return { lang: ctx.lang, urls: baseUrls }
|
||||
}
|
||||
console.info(
|
||||
"contentstack.languageSwitcher start ",
|
||||
JSON.stringify({
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
})
|
||||
)
|
||||
const res = await getLanguageSwitcher({
|
||||
contentType: ctx.contentType!,
|
||||
uid: ctx.uid,
|
||||
@@ -155,12 +163,12 @@ export const languageSwitcherQueryRouter = router({
|
||||
|
||||
if (!validatedLanguageSwitcherData.success) {
|
||||
console.error(
|
||||
`Failed to validate Language Switcher Data - (contentType: ${ctx.contentType}, lang: ${ctx.lang}, uid: ${ctx.uid})`
|
||||
"contentstack.languageSwitcher validation error",
|
||||
JSON.stringify(validatedLanguageSwitcherData.error)
|
||||
)
|
||||
console.error(validatedLanguageSwitcherData.error)
|
||||
return null
|
||||
}
|
||||
|
||||
console.info("contentstack.languageSwitcher success")
|
||||
return {
|
||||
lang: ctx.lang,
|
||||
urls,
|
||||
|
||||
@@ -37,7 +37,7 @@ import {
|
||||
export const loyaltyPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
console.info("contentstack.loyaltyPage.refs start ", { lang, uid })
|
||||
const refsResponse = await request<LoyaltyPageRefsDataRaw>(
|
||||
GetLoyaltyPageRefs,
|
||||
{
|
||||
@@ -50,6 +50,10 @@ export const loyaltyPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!refsResponse.data) {
|
||||
console.error("contentstack.loyaltyPage.refs not found error", {
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
throw notFound(refsResponse)
|
||||
}
|
||||
|
||||
@@ -59,19 +63,20 @@ export const loyaltyPageQueryRouter = router({
|
||||
validateLoyaltyPageRefsSchema.safeParse(cleanedData)
|
||||
if (!validatedLoyaltyPageRefs.success) {
|
||||
console.error(
|
||||
`Failed to validate Loyaltypage Refs - (lang: ${lang}, uid: ${uid})`
|
||||
"contentstack.loyaltyPage.refs validation error",
|
||||
{ lang, uid },
|
||||
JSON.stringify(validatedLoyaltyPageRefs.error)
|
||||
)
|
||||
console.error(validatedLoyaltyPageRefs.error)
|
||||
return null
|
||||
}
|
||||
|
||||
console.info("contentstack.loyaltyPage.refs success ", { lang, uid })
|
||||
const connections = getConnections(validatedLoyaltyPageRefs.data)
|
||||
|
||||
const tags = [
|
||||
generateTags(lang, connections),
|
||||
generateTag(lang, validatedLoyaltyPageRefs.data.loyalty_page.system.uid),
|
||||
].flat()
|
||||
|
||||
console.info("contentstack.loyaltyPage start ", { lang, uid })
|
||||
const response = await request<any>(
|
||||
GetLoyaltyPage,
|
||||
{
|
||||
@@ -82,6 +87,7 @@ export const loyaltyPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
console.error("contentstack.loyaltyPage not found error", { lang, uid })
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
@@ -191,9 +197,10 @@ export const loyaltyPageQueryRouter = router({
|
||||
validateLoyaltyPageSchema.safeParse(loyaltyPage)
|
||||
if (!validatedLoyaltyPage.success) {
|
||||
console.error(
|
||||
`Failed to validate Loyaltypage Data - (lang: ${lang}, uid: ${uid})`
|
||||
"contentstack.loyaltyPage validation error",
|
||||
{ lang, uid },
|
||||
JSON.stringify(validatedLoyaltyPage.error)
|
||||
)
|
||||
console.error(validatedLoyaltyPage.error)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -205,7 +212,7 @@ export const loyaltyPageQueryRouter = router({
|
||||
channel: TrackingChannelEnum["scandic-friends"],
|
||||
pageType: "loyaltycontentpage",
|
||||
}
|
||||
|
||||
console.info("contentstack.loyaltyPage success ", { lang, uid })
|
||||
// Assert LoyaltyPage type to get correct typings for RTE fields
|
||||
return {
|
||||
loyaltyPage,
|
||||
|
||||
@@ -61,7 +61,7 @@ export function mapMenuItems(menuItems: MenuItems) {
|
||||
export const navigationQueryRouter = router({
|
||||
get: contentstackBaseProcedure.query(async function ({ ctx }) {
|
||||
const { lang } = ctx
|
||||
|
||||
console.info("contentstack.myPages.navigation.ref start ", { lang })
|
||||
const refsResponse = await request<GetNavigationMyPagesRefsData>(
|
||||
GetNavigationMyPagesRefs,
|
||||
{ locale: lang },
|
||||
@@ -71,19 +71,21 @@ export const navigationQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!refsResponse.data) {
|
||||
console.error("contentstack.myPages.navigation.ref not found error ", {
|
||||
lang,
|
||||
})
|
||||
throw notFound(refsResponse)
|
||||
}
|
||||
|
||||
const validatedMyPagesNavigationRefs =
|
||||
navigationRefsPayloadSchema.safeParse(refsResponse.data)
|
||||
if (!validatedMyPagesNavigationRefs.success) {
|
||||
console.error(
|
||||
`Failed to validate My Pages Navigation Refs - (lang: ${lang}`
|
||||
)
|
||||
console.error(validatedMyPagesNavigationRefs.error)
|
||||
console.error("contentstack.myPages.navigation.ref validation error ", {
|
||||
lang,
|
||||
})
|
||||
return null
|
||||
}
|
||||
|
||||
console.info("contentstack.myPages.navigation.ref success ", { lang })
|
||||
const connections = getConnections(validatedMyPagesNavigationRefs.data)
|
||||
|
||||
const tags = [
|
||||
@@ -94,7 +96,7 @@ export const navigationQueryRouter = router({
|
||||
.system.uid
|
||||
),
|
||||
].flat()
|
||||
|
||||
console.info("contentstack.myPages.navigation start ", { lang })
|
||||
const response = await request<GetNavigationMyPagesData>(
|
||||
GetNavigationMyPages,
|
||||
{ locale: lang },
|
||||
@@ -102,6 +104,9 @@ export const navigationQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
console.error("contentstack.myPages.navigation not found error ", {
|
||||
lang,
|
||||
})
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
@@ -110,9 +115,10 @@ export const navigationQueryRouter = router({
|
||||
)
|
||||
if (!validatedMyPagesNavigation.success) {
|
||||
console.error(
|
||||
`Failed to validate My Pages Navigation Data - (lang: ${lang}`
|
||||
"contentstack.myPages.navigation validation error ",
|
||||
JSON.stringify({ lang }),
|
||||
JSON.stringify(validatedMyPagesNavigation.error)
|
||||
)
|
||||
console.error(validatedMyPagesNavigation.error)
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ export const hotelQueryRouter = router({
|
||||
params.include = include.join(",")
|
||||
}
|
||||
|
||||
console.log("api.hotels.hotel start")
|
||||
console.info("api.hotels.hotel start")
|
||||
const apiResponse = await api.get(
|
||||
`${api.endpoints.v1.hotels}/${hotelId}`,
|
||||
{
|
||||
@@ -74,7 +74,7 @@ export const hotelQueryRouter = router({
|
||||
return validatedRoom.data
|
||||
})
|
||||
: []
|
||||
console.log("api.hotels.hotel success")
|
||||
console.info("api.hotels.hotel success")
|
||||
return {
|
||||
hotel: validatedHotelData.data.data.attributes,
|
||||
roomCategories: roomCategories,
|
||||
@@ -90,12 +90,13 @@ export const hotelQueryRouter = router({
|
||||
// const apiLang = toApiLang(language)
|
||||
// params.set("hotelId", hotelId.toString())
|
||||
// params.set("language", apiLang)
|
||||
console.log("api.hotels.rates start")
|
||||
console.info("api.hotels.rates start")
|
||||
const validatedHotelData = getRatesSchema.safeParse(tempRatesData)
|
||||
|
||||
if (!tempRatesData) {
|
||||
console.error("api.hotels.rates error, ", {})
|
||||
return null
|
||||
//Can't return null here since consuming component does not handle null yet
|
||||
// return null
|
||||
}
|
||||
if (!validatedHotelData.success) {
|
||||
console.error(
|
||||
@@ -104,17 +105,18 @@ export const hotelQueryRouter = router({
|
||||
)
|
||||
throw badRequestError()
|
||||
}
|
||||
console.log("api.hotels.rates success")
|
||||
console.info("api.hotels.rates success")
|
||||
return validatedHotelData.data
|
||||
}),
|
||||
getFilters: publicProcedure
|
||||
.input(getFiltersInputSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
console.log("api.hotels.filters start")
|
||||
console.info("api.hotels.filters start")
|
||||
|
||||
if (!tempFilterData) {
|
||||
console.error("api.hotels.filters error, ", {})
|
||||
return null
|
||||
//Can't return null here since consuming component does not handle null yet
|
||||
// return null
|
||||
}
|
||||
const validateFilterData = getFiltersSchema.safeParse(tempFilterData)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user