fix(web): stop SSE reconnect loop on 4xx errors
Some checks failed
CI / Lint (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Broker tests (Postgres) (push) Has been cancelled
CI / Docker build (linux/amd64) (push) Has been cancelled

A revoked api key or missing topic returned by GET /v1/.../stream
used to throw inside the catch and bounce through the backoff loop
forever. Now any 4xx response terminates the loop and surfaces the
status + body in the panel error so the user sees the real cause.
5xx and network errors still reconnect.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-05-02 19:19:25 +01:00
parent a75483b3c2
commit 7af61e121e

View File

@@ -243,6 +243,15 @@ export function TopicChatPanel({
cache: "no-store",
},
);
// 4xx is terminal — auth invalid, key revoked, topic gone.
// Reconnecting won't fix any of those, so surface the error
// and stop. 5xx and network errors fall through to backoff.
if (res.status >= 400 && res.status < 500) {
const body = await res.text().catch(() => "");
setError(`stream halted: ${res.status} ${body.slice(0, 200)}`);
setStreamState("stopped");
return;
}
if (!res.ok || !res.body) {
throw new Error(`stream open failed: ${res.status}`);
}