fix: structure logged data
This commit is contained in:
@@ -35,7 +35,10 @@ import { RTEDocument } from "@/types/rte/node"
|
||||
export const accountPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
console.info(
|
||||
"contentstack.accountPage.refs start",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
const refsResponse = await request<AccountPageRefsDataRaw>(
|
||||
GetAccountPageRefs,
|
||||
{
|
||||
@@ -48,6 +51,10 @@ export const accountPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!refsResponse.data) {
|
||||
console.error(
|
||||
"contentstack.accountPage.refs not found error",
|
||||
JSON.stringify({ query: { lang, uid }, error: refsResponse })
|
||||
)
|
||||
throw notFound(refsResponse)
|
||||
}
|
||||
|
||||
@@ -56,8 +63,13 @@ export const accountPageQueryRouter = router({
|
||||
const validatedAccountPageRefs =
|
||||
validateAccountPageRefsSchema.safeParse(cleanedData)
|
||||
if (!validatedAccountPageRefs.success) {
|
||||
console.error(`Failed to validate My Page Refs - (uid: ${uid})`)
|
||||
console.error(validatedAccountPageRefs.error)
|
||||
console.error(
|
||||
"contentstack.accountPage.refs validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedAccountPageRefs.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -67,7 +79,10 @@ export const accountPageQueryRouter = router({
|
||||
generateTags(lang, connections),
|
||||
generateTag(lang, validatedAccountPageRefs.data.account_page.system.uid),
|
||||
].flat()
|
||||
console.info("contentstack.accountPage start ", { lang, uid })
|
||||
console.info(
|
||||
"contentstack.accountPage start",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
const response = await request<AccountPageDataRaw>(
|
||||
GetAccountPage,
|
||||
{
|
||||
@@ -78,7 +93,13 @@ export const accountPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
console.error("contentstack.accountPage not found error", { lang, uid })
|
||||
console.error(
|
||||
"contentstack.accountPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: response,
|
||||
})
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
@@ -89,11 +110,17 @@ export const accountPageQueryRouter = router({
|
||||
if (!validatedAccountPage.success) {
|
||||
console.error(
|
||||
"contentstack.accountPage validation error",
|
||||
JSON.stringify(validatedAccountPage.error)
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedAccountPage.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.accountPage success ", { lang, uid })
|
||||
console.info(
|
||||
"contentstack.accountPage success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
// TODO: Make returned data nicer
|
||||
const content = validatedAccountPage.data.account_page.content.map(
|
||||
(block) => {
|
||||
|
||||
@@ -33,16 +33,18 @@ import {
|
||||
export const baseQueryRouter = router({
|
||||
contact: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||
const { lang } = ctx
|
||||
console.info("contentstack.config start ", JSON.stringify({ lang }))
|
||||
console.info(
|
||||
"contentstack.config start",
|
||||
JSON.stringify({ query: { 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)
|
||||
"contentstack.config not found error",
|
||||
JSON.stringify({ query: { lang }, error: response })
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
@@ -53,29 +55,34 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!validatedContactConfigConfig.success) {
|
||||
console.error(
|
||||
"contentstack.config validation error ",
|
||||
JSON.stringify({ lang }),
|
||||
JSON.stringify(validatedContactConfigConfig.error)
|
||||
"contentstack.config validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedContactConfigConfig.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.config success ", JSON.stringify({ lang }))
|
||||
console.info(
|
||||
"contentstack.config success",
|
||||
JSON.stringify({ query: { 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 })
|
||||
"contentstack.header.ref start",
|
||||
JSON.stringify({ query: { lang: input.lang } })
|
||||
)
|
||||
const responseRef = await request<HeaderRefDataRaw>(GetCurrentHeaderRef, {
|
||||
locale: input.lang,
|
||||
})
|
||||
console.info(
|
||||
"contentstack.header. start ",
|
||||
"contentstack.header start",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
query: { lang: input.lang },
|
||||
})
|
||||
)
|
||||
|
||||
@@ -95,11 +102,13 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
console.error(
|
||||
"contentstack.header not found error ",
|
||||
"contentstack.header not found error",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
}),
|
||||
JSON.stringify(response)
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
error: response,
|
||||
})
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
@@ -112,16 +121,18 @@ export const baseQueryRouter = router({
|
||||
console.error(
|
||||
"contentstack.header validation error",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
}),
|
||||
JSON.stringify(validatedHeaderConfig.error)
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
error: validatedHeaderConfig.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info(
|
||||
"contentstack.header success ",
|
||||
"contentstack.header success",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
query: { lang: input.lang },
|
||||
})
|
||||
)
|
||||
const logo =
|
||||
@@ -136,15 +147,20 @@ export const baseQueryRouter = router({
|
||||
footer: contentstackBaseProcedure
|
||||
.input(langInput)
|
||||
.query(async ({ input }) => {
|
||||
console.info("contentstack.footer.ref start ", { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.footer.ref start",
|
||||
JSON.stringify({ query: { 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 ",
|
||||
"contentstack.footer start",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
})
|
||||
)
|
||||
const response = await request<FooterDataRaw>(
|
||||
@@ -164,11 +180,13 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
console.error(
|
||||
"contentstack.footer not found error ",
|
||||
"contentstack.footer not found error",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
}),
|
||||
JSON.stringify(response)
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
error: response,
|
||||
})
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
@@ -180,12 +198,17 @@ export const baseQueryRouter = router({
|
||||
if (!validatedFooterConfig.success) {
|
||||
console.error(
|
||||
"contentstack.footer validation error",
|
||||
JSON.stringify({ lang: input.lang }),
|
||||
JSON.stringify(validatedFooterConfig.error)
|
||||
JSON.stringify({
|
||||
query: { lang: input.lang },
|
||||
error: validatedFooterConfig.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.footer success ", { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.footer success",
|
||||
JSON.stringify({ query: { lang: input.lang } })
|
||||
)
|
||||
return validatedFooterConfig.data.all_current_footer.items[0]
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -8,7 +8,12 @@ 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 }))
|
||||
console.info(
|
||||
"contentstack.hotelPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
const response = await request<HotelPageDataRaw>(GetHotelPage, {
|
||||
locale: lang,
|
||||
uid,
|
||||
@@ -16,7 +21,10 @@ export const hotelPageQueryRouter = router({
|
||||
if (!response.data) {
|
||||
console.error(
|
||||
"contentstack.hotelPage not found error",
|
||||
JSON.stringify({ lang, uid })
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: response,
|
||||
})
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
@@ -26,8 +34,10 @@ export const hotelPageQueryRouter = router({
|
||||
if (!validatedHotelPage.success) {
|
||||
console.error(
|
||||
"contentstack.hotelPage validation error",
|
||||
JSON.stringify({ lang, uid }),
|
||||
JSON.stringify(validatedHotelPage.error)
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedHotelPage.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -35,7 +45,12 @@ export const hotelPageQueryRouter = router({
|
||||
const hotelPage = {
|
||||
...validatedHotelPage.data.hotel_page,
|
||||
} as HotelPage
|
||||
|
||||
console.info(
|
||||
"contentstack.hotelPage success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
return hotelPage
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -132,11 +132,13 @@ export const languageSwitcherQueryRouter = router({
|
||||
return { lang: ctx.lang, urls: baseUrls }
|
||||
}
|
||||
console.info(
|
||||
"contentstack.languageSwitcher start ",
|
||||
"contentstack.languageSwitcher start",
|
||||
JSON.stringify({
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
query: {
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
},
|
||||
})
|
||||
)
|
||||
const res = await getLanguageSwitcher({
|
||||
@@ -164,11 +166,27 @@ export const languageSwitcherQueryRouter = router({
|
||||
if (!validatedLanguageSwitcherData.success) {
|
||||
console.error(
|
||||
"contentstack.languageSwitcher validation error",
|
||||
JSON.stringify(validatedLanguageSwitcherData.error)
|
||||
JSON.stringify({
|
||||
query: {
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
},
|
||||
error: validatedLanguageSwitcherData.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.languageSwitcher success")
|
||||
console.info(
|
||||
"contentstack.languageSwitcher success",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
},
|
||||
})
|
||||
)
|
||||
return {
|
||||
lang: ctx.lang,
|
||||
urls,
|
||||
|
||||
@@ -37,7 +37,12 @@ import {
|
||||
export const loyaltyPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
console.info("contentstack.loyaltyPage.refs start ", { lang, uid })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage.refs start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
const refsResponse = await request<LoyaltyPageRefsDataRaw>(
|
||||
GetLoyaltyPageRefs,
|
||||
{
|
||||
@@ -50,10 +55,16 @@ export const loyaltyPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!refsResponse.data) {
|
||||
console.error("contentstack.loyaltyPage.refs not found error", {
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.loyaltyPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
uid,
|
||||
},
|
||||
error: JSON.stringify(refsResponse),
|
||||
})
|
||||
)
|
||||
throw notFound(refsResponse)
|
||||
}
|
||||
|
||||
@@ -64,19 +75,31 @@ export const loyaltyPageQueryRouter = router({
|
||||
if (!validatedLoyaltyPageRefs.success) {
|
||||
console.error(
|
||||
"contentstack.loyaltyPage.refs validation error",
|
||||
{ lang, uid },
|
||||
JSON.stringify(validatedLoyaltyPageRefs.error)
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedLoyaltyPageRefs.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.loyaltyPage.refs success ", { lang, uid })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage.refs success",
|
||||
JSON.stringify({
|
||||
query: { 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 })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
const response = await request<any>(
|
||||
GetLoyaltyPage,
|
||||
{
|
||||
@@ -87,7 +110,13 @@ export const loyaltyPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
console.error("contentstack.loyaltyPage not found error", { lang, uid })
|
||||
console.error(
|
||||
"contentstack.loyaltyPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: response,
|
||||
})
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
@@ -198,8 +227,10 @@ export const loyaltyPageQueryRouter = router({
|
||||
if (!validatedLoyaltyPage.success) {
|
||||
console.error(
|
||||
"contentstack.loyaltyPage validation error",
|
||||
{ lang, uid },
|
||||
JSON.stringify(validatedLoyaltyPage.error)
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedLoyaltyPage.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -212,7 +243,10 @@ export const loyaltyPageQueryRouter = router({
|
||||
channel: TrackingChannelEnum["scandic-friends"],
|
||||
pageType: "loyaltycontentpage",
|
||||
}
|
||||
console.info("contentstack.loyaltyPage success ", { lang, uid })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
// Assert LoyaltyPage type to get correct typings for RTE fields
|
||||
return {
|
||||
loyaltyPage,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { error } from "console"
|
||||
|
||||
import {
|
||||
GetNavigationMyPages,
|
||||
GetNavigationMyPagesRefs,
|
||||
@@ -61,7 +63,10 @@ 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 })
|
||||
console.info(
|
||||
"contentstack.myPages.navigation.refs start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const refsResponse = await request<GetNavigationMyPagesRefsData>(
|
||||
GetNavigationMyPagesRefs,
|
||||
{ locale: lang },
|
||||
@@ -71,21 +76,36 @@ export const navigationQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!refsResponse.data) {
|
||||
console.error("contentstack.myPages.navigation.ref not found error ", {
|
||||
lang,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.myPages.navigation.refs not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: refsResponse,
|
||||
})
|
||||
)
|
||||
throw notFound(refsResponse)
|
||||
}
|
||||
|
||||
const validatedMyPagesNavigationRefs =
|
||||
navigationRefsPayloadSchema.safeParse(refsResponse.data)
|
||||
if (!validatedMyPagesNavigationRefs.success) {
|
||||
console.error("contentstack.myPages.navigation.ref validation error ", {
|
||||
lang,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.myPages.navigation.refs validation error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: validatedMyPagesNavigationRefs.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.myPages.navigation.ref success ", { lang })
|
||||
console.info(
|
||||
"contentstack.myPages.navigation.refs success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const connections = getConnections(validatedMyPagesNavigationRefs.data)
|
||||
|
||||
const tags = [
|
||||
@@ -96,7 +116,10 @@ export const navigationQueryRouter = router({
|
||||
.system.uid
|
||||
),
|
||||
].flat()
|
||||
console.info("contentstack.myPages.navigation start ", { lang })
|
||||
console.info(
|
||||
"contentstack.myPages.navigation start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const response = await request<GetNavigationMyPagesData>(
|
||||
GetNavigationMyPages,
|
||||
{ locale: lang },
|
||||
@@ -104,8 +127,11 @@ export const navigationQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
console.error("contentstack.myPages.navigation not found error ", {
|
||||
lang,
|
||||
console.error("contentstack.myPages.navigation not found error", {
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: response,
|
||||
})
|
||||
throw notFound(response)
|
||||
}
|
||||
@@ -115,9 +141,11 @@ export const navigationQueryRouter = router({
|
||||
)
|
||||
if (!validatedMyPagesNavigation.success) {
|
||||
console.error(
|
||||
"contentstack.myPages.navigation validation error ",
|
||||
JSON.stringify({ lang }),
|
||||
JSON.stringify(validatedMyPagesNavigation.error)
|
||||
"contentstack.myPages.navigation.payload validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedMyPagesNavigation.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -133,12 +161,20 @@ export const navigationQueryRouter = router({
|
||||
const validatedNav = getNavigationSchema.safeParse(nav)
|
||||
if (!validatedNav.success) {
|
||||
console.error(
|
||||
`Failed to validate My Pages Navigation Return Data - (lang: ${lang}`
|
||||
"contentstack.myPages.navigation validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedNav.error,
|
||||
})
|
||||
)
|
||||
|
||||
console.error(validatedNav.error)
|
||||
return null
|
||||
}
|
||||
|
||||
console.info(
|
||||
"contentstack.myPages.navigation success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
return validatedNav.data
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user