Browse Source

fix: add URL encoding and fetch timeout to community workflow API

handoff-20260429-1057
shrimbly 6 months ago
parent
commit
5dc33c632c
  1. 36
      src/app/api/community-workflows/[id]/route.ts

36
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(
{

Loading…
Cancel
Save