fix: detect auth errors in SSE clients
Audit and repair-icons clients now check the Content-Type before reading the stream. If the server returns JSON (e.g. CSRF/permission error), the error message is shown as a toast instead of silently consuming the response as an empty SSE stream.
This commit is contained in:
1 parent
bebd65c056
commit
e4b6d5db21
2 files changed
+26
No files matched your search
@@ -104,6 +104,19 @@ export function AuditClient() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!res.headers.get("content-type")?.includes("text/event-stream")) {
|
||||
let errMsg = "Audit failed";
|
||||
try {
|
||||
const json = await res.json();
|
||||
errMsg = json.error || errMsg;
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
toast.error(errMsg);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const reader = res.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buf = "";
|
||||
|
||||
@@ -49,6 +49,19 @@ export function RepairIconsClient() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!res.headers.get("content-type")?.includes("text/event-stream")) {
|
||||
let errMsg = "Repair failed";
|
||||
try {
|
||||
const json = await res.json();
|
||||
errMsg = json.error || errMsg;
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
toast.error(errMsg);
|
||||
setRunning(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const reader = res.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buf = "";
|
||||
|
||||
Reference in new issue
Block a user