diff --git a/packages/qoder/index.mjs b/packages/qoder/index.mjs index 3598262..51ca2e9 100644 --- a/packages/qoder/index.mjs +++ b/packages/qoder/index.mjs @@ -1600,7 +1600,16 @@ function failure(status, text) { 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, lapsed: true } } - if (status === 429 || msg.toLowerCase().includes("quota")) return { status: 429, message: "usage limit reached: " + msg } + // Qoder's words go with the status and code they came in, and the reply + // itself when it says more than the message: a 429 that names no quota + // ("All models failed", QwenWork) is not shown as an account's limit + // with nothing to tell it apart (dsh, QwenWork flash) + if (status === 429 || msg.toLowerCase().includes("quota")) { + const raw = String(text ?? "").trim() + const seen = `Qoder replied HTTP ${status}${code ? `, code ${code}` : ""}` + const body = raw && raw !== msg ? `: ${raw.slice(0, 400)}` : "" + return { status: 429, message: `usage limit reached: ${msg} (${seen}${body})` } + } return { status, message: msg } } diff --git a/packages/qoder/package.json b/packages/qoder/package.json index e0fa094..204f188 100644 --- a/packages/qoder/package.json +++ b/packages/qoder/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-qoder-auth", - "version": "0.2.59", + "version": "0.2.60", "description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship, VPC and dedicated domains", "type": "module", "main": "./opencode.mjs", diff --git a/packages/qoder/raw-429.test.mjs b/packages/qoder/raw-429.test.mjs new file mode 100644 index 0000000..c1a2202 --- /dev/null +++ b/packages/qoder/raw-429.test.mjs @@ -0,0 +1,25 @@ +// A 429 that names no quota carries Qoder's status, code and own reply, so a +// user sees what Qoder said and not only "usage limit reached" +// (QwenWork flash through dsh: "All models failed"). +import { test, expect } from "bun:test" +import { _internal } from "./index.mjs" + +test("a 429 with no quota in it shows Qoder's status, code and reply", () => { + const body = JSON.stringify({ code: "9001", message: "All models failed", details: "{\"error\":{\"message\":\"flash: rate limited\"}}" }) + const f = _internal.failure(429, body) + expect(f.status).toBe(429) + expect(f.message.startsWith("usage limit reached: All models failed")).toBe(true) + expect(f.message).toContain("HTTP 429") + expect(f.message).toContain("code 9001") + expect(f.message).toContain("flash: rate limited") +}) + +test("an empty 429 still says its status", () => { + const f = _internal.failure(429, "") + expect(f.status).toBe(429) + expect(f.message).toContain("HTTP 429") +}) + +test("a quota code keeps its short words", () => { + expect(_internal.failure(429, JSON.stringify({ code: "112", message: "credits used up" })).message).toBe("usage limit reached: credits used up") +})