Skip to content
This repository was archived by the owner on Mar 25, 2026. It is now read-only.

Commit 5ce4e2a

Browse files
committed
fix: handle api errors during build in static params and pages
1 parent 4ee3506 commit 5ce4e2a

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/app/blog/[slug]/page.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ interface BlogPostPageProps {
1313
}
1414

1515
export async function generateStaticParams() {
16-
const entries = await getEntriesByCollection(config.site.slug, 'blog', {
17-
status: 'published'
18-
})
16+
try {
17+
const entries = await getEntriesByCollection(config.site.slug, 'blog', {
18+
status: 'published'
19+
})
1920

20-
return entries.map((entry) => ({
21-
slug: entry.slug
22-
}))
21+
return entries.map((entry) => ({
22+
slug: entry.slug
23+
}))
24+
} catch (error) {
25+
console.error('Failed to generate static params for blog posts:', error)
26+
return []
27+
}
2328
}
2429

2530
export async function generateMetadata({ params }: BlogPostPageProps): Promise<Metadata> {

src/app/blog/page.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { config } from '@/lib/config'
33
import { generatePageMetadata } from '@/lib/metadata'
44
import { BlogListing } from '@/components/blog/blog-listing'
55

6-
import type { BlogEntryData } from '@/types/rush-cms'
6+
import type { BlogEntryData, RushCMSEntry } from '@/types/rush-cms'
77
import type { Metadata } from 'next'
88

99
export async function generateMetadata(): Promise<Metadata> {
@@ -18,9 +18,17 @@ export async function generateMetadata(): Promise<Metadata> {
1818
}
1919

2020
export default async function BlogPage() {
21-
const entries = await getEntriesByCollection<BlogEntryData>(config.site.slug, 'blog', {
22-
status: 'published'
23-
})
21+
let entries: RushCMSEntry<BlogEntryData>[] = []
22+
23+
try {
24+
const result = await getEntriesByCollection<BlogEntryData>(config.site.slug, 'blog', {
25+
status: 'published'
26+
})
27+
entries = Array.isArray(result) ? result : []
28+
} catch (error) {
29+
console.error('Failed to fetch blog entries:', error)
30+
entries = []
31+
}
2432

2533
return (
2634
<div className='w-full max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8 sm:py-12 lg:py-16'>

0 commit comments

Comments
 (0)