fix: add improved logging for contentstack requests

This commit is contained in:
Arvid Norlin
2024-08-21 16:01:50 +02:00
parent 7de8a184b7
commit d603f53240
7 changed files with 131 additions and 44 deletions

View File

@@ -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
}