From 3f7cad905360337ee24d66ccefcb9d629b7a440a Mon Sep 17 00:00:00 2001 From: DrMint Date: Fri, 27 May 2022 16:50:10 +0200 Subject: [PATCH] Fixed 500 errors throughout the app --- src/graphql/getPostStaticProps.ts | 2 +- src/pages/archives/videos/v/[uid].tsx | 2 +- src/pages/contents/[slug]/index.tsx | 2 +- src/pages/library/[slug]/scans.tsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/graphql/getPostStaticProps.ts b/src/graphql/getPostStaticProps.ts index 4913b9c..16c6590 100644 --- a/src/graphql/getPostStaticProps.ts +++ b/src/graphql/getPostStaticProps.ts @@ -18,7 +18,7 @@ export function getPostStaticProps( slug: slug, language_code: context.locale ?? "en", }); - if (post.posts?.data[0].attributes?.translations) { + if (post.posts?.data[0]?.attributes?.translations) { const props: PostStaticProps = { ...(await getAppStaticProps(context)), post: post.posts.data[0].attributes as PostWithTranslations, diff --git a/src/pages/archives/videos/v/[uid].tsx b/src/pages/archives/videos/v/[uid].tsx index f313486..210584c 100644 --- a/src/pages/archives/videos/v/[uid].tsx +++ b/src/pages/archives/videos/v/[uid].tsx @@ -192,7 +192,7 @@ export async function getStaticProps( const videos = await sdk.getVideo({ 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 = { ...(await getAppStaticProps(context)), video: videos.videos.data[0].attributes, diff --git a/src/pages/contents/[slug]/index.tsx b/src/pages/contents/[slug]/index.tsx index 77aa093..b14e954 100644 --- a/src/pages/contents/[slug]/index.tsx +++ b/src/pages/contents/[slug]/index.tsx @@ -361,7 +361,7 @@ export async function getStaticProps( 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 }; } const props: Props = { diff --git a/src/pages/library/[slug]/scans.tsx b/src/pages/library/[slug]/scans.tsx index c705bec..4363dc6 100644 --- a/src/pages/library/[slug]/scans.tsx +++ b/src/pages/library/[slug]/scans.tsx @@ -126,7 +126,7 @@ export async function getStaticProps( slug: context.params?.slug ? context.params.slug.toString() : "", language_code: context.locale ?? "en", }); - if (!item.libraryItems) return { notFound: true }; + if (!item.libraryItems?.data[0]?.attributes) return { notFound: true }; const props: Props = { ...(await getAppStaticProps(context)), item: item.libraryItems.data[0].attributes,