Skip to content

Commit 44e8ef3

Browse files
committed
fix(frontend): show backend errors precisely
1 parent 30ec725 commit 44e8ef3

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

apps/frontend/src/app/page.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,31 @@ export default function Home() {
3939
body: form,
4040
});
4141

42-
const payload = await response.json();
42+
const rawText = await response.text();
43+
let payload: unknown = rawText;
44+
if (rawText) {
45+
try {
46+
payload = JSON.parse(rawText);
47+
} catch {
48+
payload = rawText;
49+
}
50+
}
51+
4352
if (!response.ok) {
44-
setStatus(payload?.error ?? "Scan failed");
45-
setResult(null);
46-
} else {
47-
setStatus("Scan complete");
53+
const message =
54+
typeof payload === "object" && payload !== null && "error" in payload
55+
? String((payload as { error?: string }).error)
56+
: `Scan failed (${response.status})`;
57+
setStatus(message);
58+
setResult(rawText || null);
59+
return;
60+
}
61+
62+
setStatus("Scan complete");
63+
if (payload && typeof payload === "object") {
4864
setResult(JSON.stringify(payload, null, 2));
65+
} else {
66+
setResult(rawText || null);
4967
}
5068
} catch (error) {
5169
setStatus("Failed to reach backend. Is it running on :7070?");

0 commit comments

Comments
 (0)