fix(control-plane): handle undefined response.data in graph route (#239)

When the backend graph API returns an error, the SDK sets response.data
to undefined. NextResponse.json(undefined) throws "Value is not JSON
serializable". Check for error/missing data before serializing.
This commit is contained in:
Anton Evseev 2026-01-30 18:00:56 +10:00 committed by GitHub
parent 49ae55af03
commit 751f99a82f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -24,6 +24,14 @@ export async function GET(request: NextRequest) {
},
});
if (response.error || !response.data) {
console.error("Graph API error:", response.error);
return NextResponse.json(
{ error: response.error || "Failed to fetch graph data" },
{ status: 500 },
);
}
return NextResponse.json(response.data, { status: 200 });
} catch (error) {
console.error("Error fetching graph data:", error);