Skip to content

Commit 245589b

Browse files
committed
refactor: error handling within generateMetadata
1 parent e846b65 commit 245589b

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

app/[locale]/[...slug]/page.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,18 @@ export async function generateMetadata({
114114
params: Promise<SlugPageParams>
115115
}) {
116116
const { locale, slug } = await params
117+
const t = await getTranslations({ locale, namespace: "common" })
117118

118-
const validPaths = await generateStaticParams()
119-
const isValidPath = checkPathValidity(validPaths, await params)
120-
// If invalid path, return not-found metadata title
121-
if (!isValidPath) {
122-
const t = await getTranslations("common")
123-
return { title: t("we-couldnt-find-that-page") }
119+
try {
120+
return await getMdMetadata({
121+
locale,
122+
slug,
123+
})
124+
} catch (error) {
125+
// Return basic metadata for invalid paths
126+
return {
127+
title: t("page-not-found"),
128+
description: t("page-not-found-description"),
129+
}
124130
}
125-
126-
return await getMdMetadata({
127-
locale,
128-
slug,
129-
})
130131
}

src/intl/en/common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@
374374
"page-languages-want-more-paragraph": "ethereum.org translators are always translating pages in as many languages as possible. To see what they're working on right now or to sign up to join them, read about our",
375375
"page-languages-words": "words",
376376
"page-last-updated": "Page last updated",
377+
"page-not-found": "Page not found",
378+
"page-not-found-description": "The requested page could not be found.",
377379
"participate": "Participate",
378380
"participate-menu": "Participate menu",
379381
"payments-page": "Payments",

0 commit comments

Comments
 (0)