Skip to content

Commit 5c3b33d

Browse files
authored
Merge pull request #122 from AppFlowy-IO/error_log
chore: add logs
2 parents 1a0439e + e787983 commit 5c3b33d

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

app/blog/[slug]/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ async function getData(slug: string) {
107107

108108
return { post, relatedPosts };
109109
} catch(error) {
110+
console.error(`[getData] Failed to get data for slug: "${slug}"`);
111+
console.error(`[getData] Error:`, error);
110112
notFound();
111113
}
112114
}

lib/posts.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ export async function getPostData(slug: string): Promise<PostData> {
5656
const fileName = fileNames.find((name) => name.includes(slug))!;
5757

5858
if(!fileName) {
59+
console.error(`[getPostData] Post not found for slug: "${slug}"`);
60+
console.error(`[getPostData] Posts directory: ${postsDirectory}`);
61+
console.error(`[getPostData] Available files (${fileNames.length} total):`, fileNames.slice(0, 10));
62+
console.error(`[getPostData] Searched with: name.includes("${slug}")`);
5963
throw new Error('Post not found');
6064
}
6165

@@ -65,9 +69,19 @@ export async function getPostData(slug: string): Promise<PostData> {
6569
export async function getRelatedPosts(post: PostData): Promise<PostData[]> {
6670
const relatedPosts = post.related_posts || [];
6771

68-
const posts = await Promise.all(relatedPosts.map((slug) => getPostData(slug)));
69-
70-
return posts.filter((item) => !item.unpublished);
72+
const posts = await Promise.all(
73+
relatedPosts.map(async (slug) => {
74+
try {
75+
return await getPostData(slug);
76+
} catch (error) {
77+
console.error(`[getRelatedPosts] Failed to load related post with slug: "${slug}" for post: "${post.slug}"`);
78+
console.error(`[getRelatedPosts] Error:`, error);
79+
return null;
80+
}
81+
})
82+
);
83+
84+
return posts.filter((item) => item !== null && !item.unpublished) as PostData[];
7185
}
7286

7387
export function getPostByFilename(fileName: string): PostData {

0 commit comments

Comments
 (0)