From 3d94a667f6615cd5d47eb71bb29984e75ec44099 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 1 Oct 2026 03:43:39 +0800 Subject: [PATCH] =?UTF-8?q?cursor=200.1.4:=20an=20error=20Cursor=20gives?= =?UTF-8?q?=20no=20words=20for=20is=20worded=20as=20magpie's=20built-in=20?= =?UTF-8?q?words=20it,=20Go's=20status=20text=20("Payment=20Required",=20"?= =?UTF-8?q?Too=20Many=20Requests",=20"Unauthorized=20=E2=80=94=20sign=20in?= =?UTF-8?q?=20to=20Cursor=20again"),=20where=20it=20read=20"HTTP=20402":?= =?UTF-8?q?=20a=20402=20now=20reads=20as=20the=20credit=20refusal=20it=20i?= =?UTF-8?q?s=20to=20magpie's=20routing,=20as=20the=20built-in's=20did.=20S?= =?UTF-8?q?tatuses=20were=20already=20the=20built-in's=20(resource=5Fexhau?= =?UTF-8?q?sted/quota/rate=20limit/usage=20limit=20429=20"usage=20limit=20?= =?UTF-8?q?reached:=20=E2=80=A6",=20too=20long=20400,=20invalid=5Fargument?= =?UTF-8?q?=20400,=20unavailable=20503,=20permission=5Fdenied=20403,=20oth?= =?UTF-8?q?er=20codes=20502,=20pre-content=20stream=20errors=20answered=20?= =?UTF-8?q?with=20their=20status);=20errors.test.mjs=20checks=20them=20all?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cursor/errors.test.mjs | 26 ++++++++++++++++++++++++++ packages/cursor/index.mjs | 2 +- packages/cursor/package.json | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 packages/cursor/errors.test.mjs diff --git a/packages/cursor/errors.test.mjs b/packages/cursor/errors.test.mjs new file mode 100644 index 0000000..beb084b --- /dev/null +++ b/packages/cursor/errors.test.mjs @@ -0,0 +1,26 @@ +// A request Cursor fails is answered with the status and words magpie's +// built-in Cursor (internal/gateway/cursor.go, cursorFailure) gave it, so the +// gateway moves on to the next account or member as it did. +import { expect, test } from "bun:test" +import { _internal } from "./index.mjs" + +const { failure } = _internal + +test("an HTTP error that says nothing is worded as Go's status text", () => { + expect(failure(402, "")).toEqual({ status: 402, message: "Payment Required" }) + expect(failure(429, "")).toEqual({ status: 429, message: "Too Many Requests" }) + expect(failure(503, "{}")).toEqual({ status: 503, message: "Service Unavailable" }) +}) + +test("the codes and words map as the built-in's cursorStatus", () => { + const end = (code, message) => JSON.stringify({ error: { code, message } }) + expect(failure(200, end("resource_exhausted", "slow down"))).toEqual({ status: 429, message: "usage limit reached: slow down" }) + expect(failure(200, end("unknown", "You've hit your usage limit"))).toEqual({ status: 429, message: "usage limit reached: You've hit your usage limit" }) + expect(failure(200, end("invalid_argument", "prompt is too long"))).toEqual({ status: 400, message: "input is too long for the model's context: prompt is too long" }) + expect(failure(200, end("invalid_argument", "bad"))).toEqual({ status: 400, message: "bad" }) + expect(failure(200, end("unavailable", "busy"))).toEqual({ status: 503, message: "busy" }) + expect(failure(200, end("permission_denied", "no"))).toEqual({ status: 403, message: "no" }) + expect(failure(200, end("internal", "boom"))).toEqual({ status: 502, message: "boom" }) + expect(failure(401, "")).toEqual({ status: 401, message: "Unauthorized — sign in to Cursor again" }) + expect(failure(200, end("unauthenticated", "Error"))).toEqual({ status: 401, message: "unauthenticated — sign in to Cursor again" }) +}) diff --git a/packages/cursor/index.mjs b/packages/cursor/index.mjs index a6df5ba..5382dae 100644 --- a/packages/cursor/index.mjs +++ b/packages/cursor/index.mjs @@ -855,7 +855,7 @@ const signInExpired = (low) => low.includes("expired") && /token|session|sign[- // statusOf is the status and words for Cursor's error of this code and // message. A region the team isn't served in says so, not to sign in. function statusOf(status, code, msg) { - msg ||= `HTTP ${status}` + msg ||= statusText(status) || `HTTP ${status}` const low = msg.toLowerCase() // magpie names the provider before the message itself const out = (status, message) => ({ status, message }) diff --git a/packages/cursor/package.json b/packages/cursor/package.json index fd30c92..b1b2047 100644 --- a/packages/cursor/package.json +++ b/packages/cursor/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-cursor-auth", - "version": "0.1.3", + "version": "0.1.4", "description": "Cursor subscriptions (Pro, Pro+, Ultra, Teams) in OpenCode and magpie, through the API cursor-agent talks to", "type": "module", "main": "./index.mjs",