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 {