Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Fix crash on non-existent posts

Blue Mouse55f2c24d438b
diff --git a/web/app/pages/Blog/Post.tsx b/web/app/pages/Blog/Post.tsx
index 8f5534b96..b83c69465 100644
--- a/web/app/pages/Blog/Post.tsx
+++ b/web/app/pages/Blog/Post.tsx
@@ -22,7 +22,7 @@ export default function PostSlug() {
const { t } = useTranslation('common')
useEffect(() => {
- const meta = post.author
+ const meta = post?.author
? {
author: post.author,
}
diff --git a/web/app/utils/getPosts.ts b/web/app/utils/getPosts.ts
index 4e41fa246..e0d35290a 100644
--- a/web/app/utils/getPosts.ts
+++ b/web/app/utils/getPosts.ts
@@ -33,22 +33,14 @@ interface GetPost {
export async function getPost(slug: string, category?: string): Promise<GetPost | null> {
let post: any = null
- if (category) {
- await getBlogPostWithCategory(category, slug)
- .then((data) => {
- post = data
- })
- .catch((error) => {
- console.error(error)
- })
- } else {
- await getBlogPost(slug)
- .then((data) => {
- post = data
- })
- .catch((error) => {
- console.error(error)
- })
+ try {
+ if (category) {
+ post = await getBlogPostWithCategory(category, slug)
+ } else {
+ post = await getBlogPost(slug)
+ }
+ } catch {
+ return null
}
if (!post || _isEmpty(post)) {