fix(webui): distinguish refused vs broken task actions, handle 401 (#753)

Failed task actions in the dashboard rendered the same generic message
regardless of cause. ApiError already carried the HTTP status, but nothing
read it: a refused mutation (400/403/409 - bad input, CSRF, conflicting
state) looked identical to a broken one (5xx, network drop, timeout), and
an expired session (401, whether archied's own token cookie or an upstream
forward-auth proxy) showed a generic failure instead of prompting
re-authentication.

Add classifyActionError() in api.jsx to map a caught error to a refused /
broken / session-expired kind, and use it in tasks.jsx to render each with
distinct framing and coloring (reusing the existing warn/danger tokens
pill.css already establishes) - refused actions get "you can't do that",
broken ones get "try again, or check the daemon", and an expired session
gets a reload prompt.

Refs archie-core-h3lg.
This commit is contained in:
sam authored and GitHub committed 2026-09-06 02:34:34 +10:00
1 parent 268283eb16
commit 9e608dee5f
5 files changed
+192 -6

No files matched your search

+16
View File
@@ -51,6 +51,22 @@ export class ApiError extends Error {
}
}
// classifyActionError turns a failed operator action into a rendering
// decision. archied's own handlers already return distinguishable status
// codes for a refused mutation (400/403/409 -- bad input, missing CSRF,
// cross-origin, conflicting state) versus a broken one (5xx, or no status at
// all when fetch itself failed -- network drop, timeout); 401 additionally
// means the session -- archied's own token cookie, or an upstream
// forward-auth proxy sitting in front of it -- has expired rather than that
// the action was rejected or the daemon is unwell.
export function classifyActionError(err) {
const status = err instanceof ApiError ? err.status : undefined;
const message = err?.message || "Action failed";
if (status === 401) return { kind: "session-expired", message };
if (status >= 400 && status < 500) return { kind: "refused", message };
return { kind: "broken", message };
}
export const api = {
summary: () => req("/api/summary"),
tasks: () => req("/api/tasks"),