Skip to content

Commit 73b4ff4

Browse files
fix: add error handling and status code for LLM text generation endpoint
1 parent d4ab629 commit 73b4ff4

File tree

8 files changed

+74
-293
lines changed

8 files changed

+74
-293
lines changed

app/llms.mdx/[[...slug]]/route.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ export async function GET(
2828

2929
if (!page) notFound();
3030

31-
return new Response(await getLLMText(page), {
32-
headers: {
33-
'Content-Type': 'text/markdown',
34-
},
35-
});
31+
try {
32+
return new Response(await getLLMText(page), {
33+
headers: {
34+
'Content-Type': 'text/markdown',
35+
},
36+
});
37+
} catch (error) {
38+
console.error('Failed to generate LLM text:', error);
39+
return new Response('Error generating markdown content', { status: 500 });
40+
}
3641
}
3742

3843
export function generateStaticParams() {

lib/get-llm-txt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { source } from '@/lib/source';
1+
import { source, blogSource, scriptsSource, selfHostingSource, changelogSource, legalDocsSource } from '@/lib/source';
22
import type { InferPageType } from 'fumadocs-core/source';
33

4-
export async function getLLMText(page: InferPageType<typeof source>) {
4+
export async function getLLMText(page: InferPageType<typeof source | typeof blogSource | typeof scriptsSource | typeof selfHostingSource | typeof changelogSource | typeof legalDocsSource>) {
55
const processed = await page.data.getText('processed');
66

77
return `# ${page.data.title}

mdx-components.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {ImageZoom} from 'fumadocs-ui/components/image-zoom';
66
export function getMDXComponents(components?: MDXComponents): MDXComponents {
77
return {
88
...defaultMdxComponents,
9-
img: (props) => <ImageZoom {...(props as any)} />,
9+
img: (props) => <ImageZoom {...(props)} />,
1010
...components
1111
};
1212
}

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"generate-blog-sitemap": "tsx scripts/generate-blog-sitemap.ts",
1212
"generate-overview": "tsx scripts/generate-llm-content.ts",
1313
"generate-llm-content": "tsx scripts/generate-llm-content.ts",
14-
"validate-links": "tsx scripts/validateLinks.ts",
15-
"lint": "next lint && npm run validate-links",
14+
"validate-links": "tsx -C import scripts/validateLinks.ts",
15+
"lint": "eslint . && npm run validate-links",
1616
"postbuild": "next-sitemap && npm run generate-blog-sitemap && npm run generate-llm-content"
1717
},
1818
"dependencies": {
@@ -50,6 +50,7 @@
5050
"zod": "^4.1.12"
5151
},
5252
"devDependencies": {
53+
"@eslint/eslintrc": "^3.3.1",
5354
"@tailwindcss/postcss": "^4.1.10",
5455
"@types/mdx": "^2.0.13",
5556
"@types/node": "22.18.6",
@@ -60,7 +61,7 @@
6061
"eslint-config-next": "15.5.5",
6162
"postcss": "^8.5.6",
6263
"tailwindcss": "^4.1.10",
63-
"tsx": "^4.20.3",
64+
"tsx": "^4.20.6",
6465
"typescript": "^5.8.3"
6566
}
66-
}
67+
}

0 commit comments

Comments
 (0)