agent window: plain message when the endpoint wants a key
Deploy web Studio / deploy (push) Successful in 3m16s

A 401/403 with an HTML error page (nginx) showed as "HTTP 401: 401
Authorization Required 401 Authorization Required nginx". Now: "The endpoint
wants an API key: enter it in ⚙" before one is set, "The endpoint refused
the API key (...)" after.
This commit is contained in:
grabowski committed 2026-10-23 19:57:29 +07:00
1 parent 41554801ea
commit 36f7a9f440
2 files changed
+9 -3

No files matched your search

+7 -2
View File
@@ -91,8 +91,13 @@
var m = t;
try { var x = JSON.parse(t); m = (x.error && (x.error.message || x.error)) || x.message || x.detail || t; } catch (e) { /* plain text */ }
if (typeof m !== "string") m = JSON.stringify(m);
m = m.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
var hint = r.status === 401 || r.status === 403 ? " Check the API key (⚙)." : r.status === 404 ? " Check the endpoint: most servers want the URL ending in /v1." : "";
if (/^\s*</.test(m)) m = ""; // an HTML error page says no more than the status
m = m.replace(/\s+/g, " ").trim();
if (r.status === 401 || r.status === 403) {
return new Error(A.cfg.has_key ? "The endpoint refused the API key (HTTP " + r.status + (m ? ": " + clip(m, 200) : "") + "). Check it in ⚙."
: "The endpoint wants an API key: enter it in ⚙ (HTTP " + r.status + ").");
}
var hint = r.status === 404 ? " Check the endpoint: most servers want the URL ending in /v1." : "";
return new Error("HTTP " + r.status + (m ? ": " + clip(m, 300) : "") + hint);
});
}
+2 -1
View File
@@ -121,7 +121,8 @@ def run(pg, objects, shot, check, can_set_key):
settings()
pg.locator("#agkey").fill("wrong-key")
save()
check("401" in pg.locator("#agsetmsg").inner_text(), "a wrong key shows the endpoint's refusal: " + pg.locator("#agsetmsg").inner_text())
check("refused the API key" in pg.locator("#agsetmsg").inner_text() and "invalid api key" in pg.locator("#agsetmsg").inner_text(),
"a wrong key shows the endpoint's refusal: " + pg.locator("#agsetmsg").inner_text())
check(pg.locator("#agwho .ag-off").count() == 1, "the status dot turns red")
shot("agent-badkey.jpg")
pg.locator("#agkey").fill("test-key")