specify renderPost, new error message, try await
This commit is contained in:
parent
e646df43f2
commit
c720b929ce
1 changed files with 10 additions and 3 deletions
|
@ -16,7 +16,7 @@ import { GetServerSideProps } from "next";
|
|||
|
||||
|
||||
const Post = ({renderedPost, theme, changeTheme}: PostProps) => {
|
||||
const [post, setPost] = useState<any>()
|
||||
const [post, setPost] = useState(renderedPost);
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [error, setError] = useState<string>()
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue