qoder 0.2.12: a chat Qoder refuses (401/403) keeps Qoder's own reason in the error

Yayoi_no_yume on X: a request made right after signing in came back
"Qoder: the sign-in lapsed — sign in again" (401), and only installing and
signing in to Qoder CLI made it work. failure() replaced whatever Qoder said
with that fixed text, so the real reason for the refusal could not be seen.
The message is the same, with "(Qoder said <status>: <its message>)" added
when Qoder gave one; the account is still left unmarked (X-Magpie-Sign-In:
kept), as before.

usage.test.mjs gains the case (a 401 whose body says why); it fails on
0.2.11 and passes. bun test (89 pass) and scripts/check.mjs qoder under a
scratch HOME pass. Not tried against Qoder itself (no Qoder account here),
so the cause of the reporter's 401 is not known yet.
This commit is contained in:
yetone
2026-10-10 01:10:39 +08:00
parent 5189b287e7
commit aa2d99bd13
3 changed files with 15 additions and 4 deletions
+7 -2
View File
@@ -708,8 +708,13 @@ function failure(status, text) {
} catch {}
msg ||= STATUS_CODES[status] ?? `HTTP ${status}`
// a refused chat is the built-in's 401, which never marked the account
// lapsed: only a refused refresh did (errorResponse says kept)
if (status === 401 || status === 403) return { status: 401, message: "the sign-in lapsed — sign in again" }
// lapsed: only a refused refresh did (errorResponse says kept). Qoder's
// own words go with it: a 401 right after signing in isn't a lapsed
// sign-in, and its reason is what says what is (Yayoi_no_yume on X).
if (status === 401 || status === 403) {
const said = msg && msg !== STATUS_CODES[status] ? ` (Qoder said ${status}: ${msg.slice(0, 300)})` : ""
return { status: 401, message: "the sign-in lapsed — sign in again" + said }
}
if (status === 429 || msg.toLowerCase().includes("quota")) return { status: 429, message: "usage limit reached: " + msg }
return { status, message: msg }
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-qoder-auth",
"version": "0.2.11",
"version": "0.2.12",
"description": "Qoder subscriptions in OpenCode and magpie: Qoder (qoder.com) and Qoder CN (qoder.cn)",
"type": "module",
"main": "./index.mjs",
+7 -1
View File
@@ -151,12 +151,18 @@ const ASK = { method: "POST", body: JSON.stringify({ model: "qmodel", messages:
test("a refused chat, 401 or 403, is the built-in's 401 and leaves the account unmarked", async () => {
for (const status of [401, 403]) {
const { fetch } = await chat(LISTING, () => new Response("nope", { status }))
const { fetch } = await chat(LISTING, () => new Response("", { status }))
const res = await fetch(API_CHAT, ASK)
expect(res.status).toBe(401)
expect(res.headers.get("X-Magpie-Sign-In")).toBe("kept")
expect((await res.json()).error.message).toBe("the sign-in lapsed — sign in again")
}
// what Qoder says of the refusal is kept: a 401 just after signing in
// has some other reason, and only Qoder's words tell it
const said = await chat(LISTING, () => new Response(JSON.stringify({ message: "device not trusted" }), { status: 401 }))
const r = await said.fetch(API_CHAT, ASK)
expect([r.status, r.headers.get("X-Magpie-Sign-In")]).toEqual([401, "kept"])
expect((await r.json()).error.message).toBe("the sign-in lapsed — sign in again (Qoder said 401: device not trusted)")
// refused in the stream, before any answer: the same
const sse = (v) => new Response(`data: ${JSON.stringify(v)}\n\n`, { headers: { "Content-Type": "text/event-stream" } })
const { fetch } = await chat(LISTING, () => sse({ statusCodeValue: 403, body: "" }))