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:
parent
49ae55af03
commit
751f99a82f
1 changed files with 8 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue