agent window: plain message when the endpoint wants a key
Deploy web Studio / deploy (push) Successful in 3m16s
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:
1 parent
41554801ea
commit
36f7a9f440
2 files changed
+9
-3
No files matched your search
+7
-2
@@ -91,8 +91,13 @@
|
|||||||
var m = t;
|
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 */ }
|
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);
|
if (typeof m !== "string") m = JSON.stringify(m);
|
||||||
m = m.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
if (/^\s*</.test(m)) m = ""; // an HTML error page says no more than the status
|
||||||
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." : "";
|
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);
|
return new Error("HTTP " + r.status + (m ? ": " + clip(m, 300) : "") + hint);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,8 @@ def run(pg, objects, shot, check, can_set_key):
|
|||||||
settings()
|
settings()
|
||||||
pg.locator("#agkey").fill("wrong-key")
|
pg.locator("#agkey").fill("wrong-key")
|
||||||
save()
|
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")
|
check(pg.locator("#agwho .ag-off").count() == 1, "the status dot turns red")
|
||||||
shot("agent-badkey.jpg")
|
shot("agent-badkey.jpg")
|
||||||
pg.locator("#agkey").fill("test-key")
|
pg.locator("#agkey").fill("test-key")
|
||||||
|
|||||||
Reference in new issue
Block a user