From 5dc33c632ce06b29c3939fc63409fc324148cc36 Mon Sep 17 00:00:00 2001 From: shrimbly Date: Thu, 22 Jan 2026 06:37:52 +1300 Subject: [PATCH] fix: add URL encoding and fetch timeout to community workflow API --- src/app/api/community-workflows/[id]/route.ts | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/app/api/community-workflows/[id]/route.ts b/src/app/api/community-workflows/[id]/route.ts index b9670925..bb09144c 100644 --- a/src/app/api/community-workflows/[id]/route.ts +++ b/src/app/api/community-workflows/[id]/route.ts @@ -16,16 +16,25 @@ interface RouteParams { * community workflows in R2 storage. */ export async function GET(request: Request, { params }: RouteParams) { + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout + try { const { id } = await params; - const response = await fetch(`${COMMUNITY_WORKFLOWS_API_URL}/${id}`, { - headers: { - Accept: "application/json", - }, - // Cache for 10 minutes (individual workflows change less frequently) - next: { revalidate: 600 }, - }); + const response = await fetch( + `${COMMUNITY_WORKFLOWS_API_URL}/${encodeURIComponent(id)}`, + { + headers: { + Accept: "application/json", + }, + signal: controller.signal, + // Cache for 10 minutes (individual workflows change less frequently) + next: { revalidate: 600 }, + } + ); + + clearTimeout(timeoutId); if (!response.ok) { if (response.status === 404) { @@ -56,6 +65,19 @@ export async function GET(request: Request, { params }: RouteParams) { return NextResponse.json(data); } catch (error) { + clearTimeout(timeoutId); + + if (error instanceof Error && error.name === "AbortError") { + console.error("Community workflow fetch timed out"); + return NextResponse.json( + { + success: false, + error: "Request timed out", + }, + { status: 504 } + ); + } + console.error("Error loading community workflow:", error); return NextResponse.json( {