Skip to content

The agent that grows with you

fix(web): show a structured error detail's message instead of the status sentence

John Paul Soliva92eaf21eb502
diff --git a/web/src/lib/api-error.test.ts b/web/src/lib/api-error.test.ts
index 0e9abaa56a3..eb2668a37ba 100644
--- a/web/src/lib/api-error.test.ts
+++ b/web/src/lib/api-error.test.ts
@@ -51,6 +51,26 @@ describe("fetchJSON error contract", () => {
expect(`${errorMessage(apiErr)}`).not.toMatch(/^Error:/);
});
+ it("shows a structured detail's message, not the generic status sentence", async () => {
+ // The corrupt state.db 503 from the analytics routes (web_routers/_common.py CORRUPT_STORE_DETAIL).
+ const body = {
+ detail: {
+ error: "state_db_corrupt",
+ message: "state.db corrupt — run `hermes doctor` (then `hermes doctor --fix` or `hermes sessions repair`).",
+ path: "/home/u/.hermes/state.db",
+ },
+ };
+ vi.stubGlobal(
+ "fetch",
+ vi.fn<typeof fetch>(async () => new Response(JSON.stringify(body), { status: 503 })),
+ );
+
+ const err = (await fetchJSON("/api/analytics/models?days=7").catch((e: unknown) => e)) as ApiError;
+ expect(err).toBeInstanceOf(ApiError);
+ expect(err.message).toBe(body.detail.message);
+ expect(err.status).toBe(503);
+ });
+
it("maps a detail-less status to a plain sentence with no HTTP code lead", async () => {
vi.stubGlobal(
"fetch",
diff --git a/web/src/lib/api-error.ts b/web/src/lib/api-error.ts
index 13ea59c5a6d..f4ddf4f303d 100644
--- a/web/src/lib/api-error.ts
+++ b/web/src/lib/api-error.ts
@@ -50,6 +50,11 @@ export function extractDetail(body: string): string | null {
.map((item) => (item && typeof item === "object" ? (item as { msg?: unknown }).msg : null))
.filter((m): m is string => typeof m === "string");
if (msgs.length) return msgs.join("; ");
+ } else if (value && typeof value === "object") {
+ // Structured detail ({error: "<code>", message: "<sentence>"}): the code is for
+ // programs, the sentence is what the operator needs to act on.
+ const message = (value as { message?: unknown }).message;
+ if (typeof message === "string" && message.trim()) return message.trim();
}
}
}