Graceful fallback for locale pages that don't exist

This commit is contained in:
Nate Stewart 2020-10-29 11:16:20 -05:00
parent 629df7a9ab
commit 552e104516

View File

@ -19,11 +19,15 @@ export async function getStaticProps({
const data = const data =
pageItem && pageItem &&
(await getPage({ variables: { id: pageItem.id! }, config, preview })) (await getPage({ variables: { id: pageItem.id! }, config, preview }))
const page = data?.page let page = data?.page
if (!page) { if (!page) {
// We throw to make sure this fails at build time as this is never expected to happen // Fallback to generating a page with direction to fix missing content for locale, so build process can continue
throw new Error(`Page with slug '${slug}' not found`) page = {
...pages[0],
url: slug,
body: `*Missing content for locale* Add page with slug of ${slug} to resolve.`
}
} }
return { return {