Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(docs): Fix 500 error on .md endpoints

sohamganatrae415be0c0221
diff --git a/docs/app/llms.mdx/[[...slug]]/route.ts b/docs/app/llms.mdx/[[...slug]]/route.ts
index 2a4740c52..1958b6e97 100644
--- a/docs/app/llms.mdx/[[...slug]]/route.ts
+++ b/docs/app/llms.mdx/[[...slug]]/route.ts
@@ -426,60 +426,100 @@ export async function GET(
_req: Request,
{ params }: { params: Promise<{ slug?: string[] }> }
) {
- const { slug = [] } = await params;
- const [prefix, ...rest] = slug;
-
- // Find the matching source
- const match = sources.find((s) => s.prefix === prefix);
- if (!match) notFound();
-
- // Get the page from that source (MDX pages)
- const page = match.source.getPage(rest.length > 0 ? rest : undefined);
-
- if (page) {
- // Check if this is an OpenAPI page
- if ('getAPIPageProps' in page.data) {
- const markdown = await openapiPageToMarkdown(
- page as { url: string; data: OpenAPIPageData }
- );
- return new Response(markdown, {
- headers: {
- 'Content-Type': 'text/markdown; charset=utf-8',
- },
- });
- }
+ try {
+ const { slug = [] } = await params;
+ const [prefix, ...rest] = slug;
+
+ // Find the matching source
+ const match = sources.find((s) => s.prefix === prefix);
+ if (!match) notFound();
- // Regular MDX page
+ // Get the page from that source (MDX pages)
+ let page;
try {
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- return new Response(await getLLMText(page as any), {
- headers: {
- 'Content-Type': 'text/markdown; charset=utf-8',
- },
- });
- } catch {
- return new Response(
- `# ${page.data.title} (${page.url})\n\n${page.data.description || ''}`,
- {
+ page = match.source.getPage(rest.length > 0 ? rest : undefined);
+ } catch (e) {
+ console.error('Error in getPage:', e);
+ page = null;
+ }
+
+ if (page) {
+ // Check if this is an OpenAPI page
+ if ('getAPIPageProps' in page.data) {
+ try {
+ const markdown = await openapiPageToMarkdown(
+ page as { url: string; data: OpenAPIPageData }
+ );
+ return new Response(markdown, {
+ headers: {
+ 'Content-Type': 'text/markdown; charset=utf-8',
+ },
+ });
+ } catch (e) {
+ console.error('Error generating OpenAPI markdown:', e);
+ const title = page.data?.title || 'API Reference';
+ const description = page.data?.description || '';
+ return new Response(
+ `# ${title}\n\n${description}`,
+ {
+ headers: {
+ 'Content-Type': 'text/markdown; charset=utf-8',
+ },
+ }
+ );
+ }
+ }
+
+ // Regular MDX page
+ try {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ return new Response(await getLLMText(page as any), {
headers: {
'Content-Type': 'text/markdown; charset=utf-8',
},
- }
- );
+ });
+ } catch (e) {
+ console.error('Error generating LLM text:', e);
+ const title = page.data?.title || 'Documentation';
+ const description = page.data?.description || '';
+ return new Response(
+ `# ${title} (${page.url || ''})\n\n${description}`,
+ {
+ headers: {
+ 'Content-Type': 'text/markdown; charset=utf-8',
+ },
+ }
+ );
+ }
+ }
+
+ // Special handling for JSON toolkit pages
+ if (prefix === 'toolkits' && rest.length === 1) {
+ const toolkit = await getToolkit(rest[0]);
+ if (toolkit) {
+ return new Response(toolkitToMarkdown(toolkit), {
+ headers: {
+ 'Content-Type': 'text/markdown; charset=utf-8',
+ },
+ });
+ }
}
- }
- // Special handling for JSON toolkit pages
- if (prefix === 'toolkits' && rest.length === 1) {
- const toolkit = await getToolkit(rest[0]);
- if (toolkit) {
- return new Response(toolkitToMarkdown(toolkit), {
+ notFound();
+ } catch (e) {
+ // Don't catch notFound - let it propagate
+ if (e && typeof e === 'object' && 'digest' in e) {
+ throw e;
+ }
+ console.error('Unexpected error in llms.mdx route:', e);
+ return new Response(
+ '# Error\n\nAn error occurred while generating the markdown content.',
+ {
+ status: 500,
headers: {
'Content-Type': 'text/markdown; charset=utf-8',
},
- });
- }
+ }
+ );
}
-
- notFound();
}
diff --git a/docs/lib/source.ts b/docs/lib/source.ts
index 511323f34..4d45a3c1e 100644
--- a/docs/lib/source.ts
+++ b/docs/lib/source.ts
@@ -165,7 +165,15 @@ function mdxToCleanMarkdown(content: string): string {
}
export async function getLLMText(page: InferPageType<typeof source>) {
- const content = await page.data.getText('raw');
+ // Use 'processed' mode since that's what includeProcessedMarkdown enables
+ // Fall back to description if getText is not available
+ if (typeof page.data.getText !== 'function') {
+ return `# ${page.data.title} (${page.url})
+
+${page.data.description || ''}`;
+ }
+
+ const content = await page.data.getText('processed');
const cleanContent = mdxToCleanMarkdown(content);
return `# ${page.data.title} (${page.url})