Fixed 500 errors throughout the app

This commit is contained in:
DrMint 2022-05-27 16:50:10 +02:00
parent 2dee361f20
commit 3f7cad9053
4 changed files with 4 additions and 4 deletions

View File

@ -18,7 +18,7 @@ export function getPostStaticProps(
slug: slug, slug: slug,
language_code: context.locale ?? "en", language_code: context.locale ?? "en",
}); });
if (post.posts?.data[0].attributes?.translations) { if (post.posts?.data[0]?.attributes?.translations) {
const props: PostStaticProps = { const props: PostStaticProps = {
...(await getAppStaticProps(context)), ...(await getAppStaticProps(context)),
post: post.posts.data[0].attributes as PostWithTranslations, post: post.posts.data[0].attributes as PostWithTranslations,

View File

@ -192,7 +192,7 @@ export async function getStaticProps(
const videos = await sdk.getVideo({ const videos = await sdk.getVideo({
uid: context.params?.uid ? context.params.uid.toString() : "", uid: context.params?.uid ? context.params.uid.toString() : "",
}); });
if (!videos.videos?.data[0].attributes) return { notFound: true }; if (!videos.videos?.data[0]?.attributes) return { notFound: true };
const props: Props = { const props: Props = {
...(await getAppStaticProps(context)), ...(await getAppStaticProps(context)),
video: videos.videos.data[0].attributes, video: videos.videos.data[0].attributes,

View File

@ -361,7 +361,7 @@ export async function getStaticProps(
language_code: context.locale ?? "en", language_code: context.locale ?? "en",
}); });
if (!content.contents || !content.contents.data[0].attributes?.translations) { if (!content.contents || !content.contents.data[0]?.attributes?.translations) {
return { notFound: true }; return { notFound: true };
} }
const props: Props = { const props: Props = {

View File

@ -126,7 +126,7 @@ export async function getStaticProps(
slug: context.params?.slug ? context.params.slug.toString() : "", slug: context.params?.slug ? context.params.slug.toString() : "",
language_code: context.locale ?? "en", language_code: context.locale ?? "en",
}); });
if (!item.libraryItems) return { notFound: true }; if (!item.libraryItems?.data[0]?.attributes) return { notFound: true };
const props: Props = { const props: Props = {
...(await getAppStaticProps(context)), ...(await getAppStaticProps(context)),
item: item.libraryItems.data[0].attributes, item: item.libraryItems.data[0].attributes,