Skip to content

Commit 07fc9ad

Browse files
Add error handling for examples API route
1 parent b26e08e commit 07fc9ad

File tree

1 file changed

+13
-5
lines changed
  • src/pages/api/[version]/[section]/[page]/[tab]

1 file changed

+13
-5
lines changed

src/pages/api/[version]/[section]/[page]/[tab]/examples.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ export const GET: APIRoute = async ({ params, url }) => {
1515
}
1616

1717
// Get examples with titles directly from the index
18-
const index = await fetchApiIndex(url)
19-
const tabKey = createIndexKey(version, section, page, tab)
20-
const examples = index.examples[tabKey] || []
21-
22-
return createJsonResponse(examples)
18+
try {
19+
const index = await fetchApiIndex(url)
20+
const tabKey = createIndexKey(version, section, page, tab)
21+
const examples = index.examples[tabKey] || []
22+
23+
return createJsonResponse(examples)
24+
} catch (error) {
25+
const details = error instanceof Error ? error.message : String(error)
26+
return createJsonResponse(
27+
{ error: 'Failed to load API index', details },
28+
500,
29+
)
30+
}
2331
}
2432

2533

0 commit comments

Comments
 (0)