Files
web/app/[lang]/(preview-current)/preview-current/page.tsx
Michael Zetterberg 71dcf30719 fix: make sure all logged errors are preceeded with a message
Just logging an error makes it difficult to relate the error log to code in the
codebase. Error logging a message right before the error itself makes it easier
to search the codebase for that error log.
2024-07-24 11:32:15 +02:00

43 lines
1.4 KiB
TypeScript

import ContentstackLivePreview from "@contentstack/live-preview-utils"
import { previewRequest } from "@/lib/graphql/previewRequest"
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql"
import ContentPage from "@/components/Current/ContentPage"
import LoadingSpinner from "@/components/Current/LoadingSpinner"
import type { LangParams, PageArgs, PreviewParams } from "@/types/params"
import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage"
export default async function CurrentPreviewPage({
params,
searchParams,
}: PageArgs<LangParams, PreviewParams>) {
try {
ContentstackLivePreview.setConfigFromParams(searchParams)
if (!searchParams.uri || !searchParams.live_preview) {
return <LoadingSpinner />
}
const response = await previewRequest<GetCurrentBlockPageData>(
GetCurrentBlockPage,
{ locale: params.lang, url: searchParams.uri }
)
if (!response.data?.all_current_blocks_page?.total) {
console.log("#### DATA ####")
console.log(response.data)
console.log("SearchParams URI: ", searchParams.uri)
throw new Error("Not found")
}
return <ContentPage data={response.data} />
} catch (error) {
// TODO: throw 500
console.error("Error in current preview page")
console.error(error)
throw new Error("Something went wrong")
}
}