fix: add error handling

This commit is contained in:
Taqib
2025-07-23 15:59:47 +01:00
parent 184dcbabef
commit f39f46788f
+9 -3
View File
@@ -3,6 +3,7 @@ import { getPosts } from '@/lib/blog-query';
import { SITE_INFO } from '../metadata'; import { SITE_INFO } from '../metadata';
export async function GET() { export async function GET() {
try {
const { posts } = await getPosts(); const { posts } = await getPosts();
const feed = new Feed({ const feed = new Feed({
@@ -25,16 +26,21 @@ export async function GET() {
link: `${SITE_INFO.url}/blog/${post.slug}`, link: `${SITE_INFO.url}/blog/${post.slug}`,
description: post.description, description: post.description,
author: post.authors.map((author) => ({ author: post.authors.map((author) => ({
name: post.name ?? 'OpenCut', name: author.name,
})), })),
date: new Date(post.publishedAt), date: new Date(post.publishedAt),
image: post.coverImage, image: post.coverImage || SITE_INFO.openGraphImage,
});
}); });
}
return new Response(feed.rss2(), { return new Response(feed.rss2(), {
headers: { headers: {
'Content-Type': 'text/xml', 'Content-Type': 'text/xml',
'Cache-Control': 'public, max-age=86400, stale-while-revalidate',
}, },
}); });
} catch (error) {
console.error('Error generating RSS feed', error);
return new Response('Internal Server Error', { status: 500 });
}
} }