@devries-cameron20 / composio-1 / commits / bda787e2b
Fork 0

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): add error handling to search API for debugging

Wrap search handler initialization in try-catch to capture and log actual errors in production serverless environment. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Sushmithamallesh committed Jan 16, 2026 at 13:16 UTC bda787e2b78447c3e716eafbf8a1dcfff6043eec
1 file changed +31 -11
docs/app/api/search/route.ts
+31 -11
@@ -6,22 +6,42 @@ import {
6 toolkitsSource,
7 } from '@/lib/source';
8 import { createSearchAPI } from 'fumadocs-core/search/server';
9 +import { NextResponse } from 'next/server';
10
10 -const allPages = [
11 - ...source.getPages(),
12 - ...toolRouterSource.getPages(),
13 - ...referenceSource.getPages(),
14 - ...examplesSource.getPages(),
15 - ...toolkitsSource.getPages(),
16 -];
11 +function getSearchIndexes() {
12 + const allPages = [
13 + ...source.getPages(),
14 + ...toolRouterSource.getPages(),
15 + ...referenceSource.getPages(),
16 + ...examplesSource.getPages(),
17 + ...toolkitsSource.getPages(),
18 + ];
19
18 -export const { GET } = createSearchAPI('advanced', {
19 - indexes: allPages.map((page) => ({
20 + return allPages.map((page) => ({
21 id: page.url,
22 title: page.data.title ?? 'Untitled',
23 description: page.data.description,
24 url: page.url,
25 structuredData: page.data.structuredData,
26 keywords: 'keywords' in page.data ? page.data.keywords : undefined,
26 - })),
27 -});
27 + }));
28 +}
29 +
30 +let searchHandler: ReturnType<typeof createSearchAPI>['GET'] | null = null;
31 +
32 +export async function GET(request: Request) {
33 + try {
34 + if (!searchHandler) {
35 + const indexes = getSearchIndexes();
36 + const api = createSearchAPI('advanced', { indexes });
37 + searchHandler = api.GET;
38 + }
39 + return searchHandler(request);
40 + } catch (error) {
41 + console.error('Search API error:', error);
42 + return NextResponse.json(
43 + { error: 'Search failed', message: String(error) },
44 + { status: 500 }
45 + );
46 + }
47 +}