Skip to content

Commit 814b427

Browse files
[cueweb] Fix addsubscriber proxy: propagate HTTP status, drop JSON round-trip
- handleRoute now receives the parsed body once - removed the redundant JSON.stringify(await request.json()) + JSON.parse() pair. - HTTP status now travels via NextResponse.json's second argument ({ status: response.status }) instead of sitting inside the body, so non-2xx upstream responses surface as non-2xx to the caller. - Error path uses responseData?.error ?? 'Upstream error' to stay null-safe, matching the addcomment route's pattern.
1 parent 02a8668 commit 814b427

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

  • cueweb/app/api/job/action/addsubscriber

cueweb/app/api/job/action/addsubscriber/route.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ export async function POST(request: NextRequest) {
2424
return NextResponse.json({ error: 'Invalid method. Only POST is allowed.' }, { status: 405 });
2525
}
2626

27-
const body = JSON.stringify(await request.json());
28-
const jsonBody = JSON.parse(body);
27+
const jsonBody = await request.json();
2928
if (
3029
!jsonBody ||
3130
typeof jsonBody !== 'object' ||
@@ -36,9 +35,11 @@ export async function POST(request: NextRequest) {
3635
return NextResponse.json({ error: 'Invalid request body' }, { status: 400 });
3736
}
3837

39-
const response = await handleRoute(method, endpoint, body, true);
38+
const response = await handleRoute(method, endpoint, JSON.stringify(jsonBody), true);
4039
const responseData = await response.json();
4140

42-
if (!response.ok) return NextResponse.json({ error: responseData.error, status: response.status });
43-
return NextResponse.json({ data: responseData.data, status: responseData.status });
41+
if (!response.ok) {
42+
return NextResponse.json({ error: responseData?.error ?? 'Upstream error' }, { status: response.status });
43+
}
44+
return NextResponse.json({ data: responseData.data }, { status: response.status });
4445
}

0 commit comments

Comments
 (0)