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.
29 lines
1.4 KiB
JavaScript
29 lines
1.4 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import "./shim.js";
|
|
import { ApiError, classifyActionError } from "../src/base/api.js";
|
|
|
|
test("classifyActionError treats 401 as an expired session", () => {
|
|
assert.equal(classifyActionError(new ApiError("unauthorised", 401)).kind, "session-expired");
|
|
});
|
|
|
|
test("classifyActionError treats 400/403/409 as refused", () => {
|
|
assert.equal(classifyActionError(new ApiError("bad id", 400)).kind, "refused");
|
|
assert.equal(classifyActionError(new ApiError("cross-origin mutation refused", 403)).kind, "refused");
|
|
assert.equal(classifyActionError(new ApiError("task changed state; refresh and try again", 409)).kind, "refused");
|
|
});
|
|
|
|
test("classifyActionError treats 5xx as broken", () => {
|
|
assert.equal(classifyActionError(new ApiError("task action failed", 500)).kind, "broken");
|
|
assert.equal(classifyActionError(new ApiError("runtime task control is unavailable", 503)).kind, "broken");
|
|
});
|
|
|
|
test("classifyActionError treats a statusless error (network/timeout) as broken", () => {
|
|
assert.equal(classifyActionError(new TypeError("Failed to fetch")).kind, "broken");
|
|
assert.equal(classifyActionError(new DOMException("The operation was aborted", "AbortError")).kind, "broken");
|
|
});
|
|
|
|
test("classifyActionError preserves the server's message", () => {
|
|
assert.equal(classifyActionError(new ApiError("cross-origin mutation refused", 403)).message, "cross-origin mutation refused");
|
|
});
|