Skip to content

Commit 074522f

Browse files
committed
Add JSON parsing error handling for feedback API
1 parent e6ed8bd commit 074522f

File tree

1 file changed

+14
-5
lines changed
  • apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/support/apis

1 file changed

+14
-5
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/support/apis/feedback.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,22 @@ export async function submitSupportFeedback({
6767
return { error };
6868
}
6969

70-
const data = await response.json();
70+
try {
71+
const data = await response.json();
7172

72-
if (!data.success) {
73-
return { error: "API returned unsuccessful response" };
74-
}
73+
// Validate response structure
74+
if (typeof data !== "object" || data === null) {
75+
return { error: "Invalid response format from API" };
76+
}
77+
78+
if (!data.success) {
79+
return { error: "API returned unsuccessful response" };
80+
}
7581

76-
return { success: true };
82+
return { success: true };
83+
} catch (_jsonError) {
84+
return { error: "Invalid JSON response from API" };
85+
}
7786
} catch (error) {
7887
if (error instanceof Error) {
7988
if (error.name === "AbortError") return { error: "Request timeout" };

0 commit comments

Comments
 (0)