From c720b929ce1b36f7cd68dd0e0d7b98c2109872d9 Mon Sep 17 00:00:00 2001 From: Anton <62949848+icepaq@users.noreply.github.com> Date: Sat, 19 Mar 2022 20:15:17 -0400 Subject: [PATCH] specify renderPost, new error message, try await --- client/pages/post/[id].tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/client/pages/post/[id].tsx b/client/pages/post/[id].tsx index 374130f7..b471dcd5 100644 --- a/client/pages/post/[id].tsx +++ b/client/pages/post/[id].tsx @@ -16,7 +16,7 @@ import { GetServerSideProps } from "next"; const Post = ({renderedPost, theme, changeTheme}: PostProps) => { - const [post, setPost] = useState() + const [post, setPost] = useState(renderedPost); const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState() const router = useRouter(); @@ -35,7 +35,7 @@ const Post = ({renderedPost, theme, changeTheme}: PostProps) => { if (!Cookies.get('drift-token')) { router.push('/signin'); } else { - setError('Post Error'); + setError('Something went wrong fetching the post'); } } fetchPost() @@ -115,7 +115,14 @@ export const getServerSideProps: GetServerSideProps = async (context) => { "Content-Type": "application/json", "Authorization": `Bearer ${driftToken}` } - }).then(res => res.json()); + }); + + try { + post = await post.json(); + } catch (e) { + console.log(e); + post = null; + } } return {