Skip to content

Commit d350403

Browse files
committed
fix(articles): wrap getArticleNewPaths in try/catch so build survives Strapi HTML response
CI build was failing on /articles/[page] when Strapi returned HTML (DOCTYPE) instead of JSON — likely a Cloudflare challenge to GH Actions runner IP or a transient 502. fallback: blocking is already set on getStaticPaths, so SSG on-demand handles requests at runtime. Empty paths array just skips pre-render.
1 parent 445d87e commit d350403

1 file changed

Lines changed: 29 additions & 19 deletions

File tree

src/api/strapi.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,39 @@ export const getRecommendedArticles = (
112112
};
113113

114114
export const getArticleNewPaths = async () => {
115-
const url = `${process.env.NEXT_PUBLIC_STRAPI}/api/articles?locale=all&populate=*`;
115+
try {
116+
const url = `${process.env.NEXT_PUBLIC_STRAPI}/api/articles?locale=all&populate=*`;
116117

117-
const articles = await fetch(url)
118-
.then(resp => resp.json())
119-
.then(json => json?.data || []);
118+
const articles = await fetch(url)
119+
.then(resp => resp.json())
120+
.then(json => json?.data || []);
120121

121-
const filteredArticles = articles.filter(
122-
article => article.attributes?.newUrl !== 'company-management',
123-
);
124-
const strapiPaths = filteredArticles
125-
.map((article: TArticle) => ({
126-
params: {
127-
page: article.attributes?.newUrl || '',
128-
},
129-
locale: article?.attributes?.locale,
130-
}))
131-
.filter(
132-
(path: any) =>
133-
!path?.params?.page?.[0]?.includes('http') &&
134-
path?.params?.page?.[0] !== 'uxeducation',
122+
const filteredArticles = articles.filter(
123+
article => article.attributes?.newUrl !== 'company-management',
135124
);
125+
const strapiPaths = filteredArticles
126+
.map((article: TArticle) => ({
127+
params: {
128+
page: article.attributes?.newUrl || '',
129+
},
130+
locale: article?.attributes?.locale,
131+
}))
132+
.filter(
133+
(path: any) =>
134+
!path?.params?.page?.[0]?.includes('http') &&
135+
path?.params?.page?.[0] !== 'uxeducation',
136+
);
136137

137-
return strapiPaths;
138+
return strapiPaths;
139+
} catch (err) {
140+
// Build-time Strapi fetch can return HTML (502/maintenance) — don't fail
141+
// the whole build; rely on fallback: 'blocking' to SSG-on-demand at runtime.
142+
console.warn(
143+
'[getArticleNewPaths] build-time fetch failed, returning empty paths:',
144+
err,
145+
);
146+
return [];
147+
}
138148
};
139149

140150
export const getPyramids = async (locale: TLocales) => {

0 commit comments

Comments
 (0)