cursor 0.1.4: an error Cursor gives no words for is worded as magpie's built-in words it, Go's status text ("Payment Required", "Too Many Requests", "Unauthorized — sign in to Cursor again"), where it read "HTTP 402": a 402 now reads as the credit refusal it is to magpie's routing, as the built-in's did. Statuses were already the built-in's (resource_exhausted/quota/rate limit/usage limit 429 "usage limit reached: …", too long 400, invalid_argument 400, unavailable 503, permission_denied 403, other codes 502, pre-content stream errors answered with their status); errors.test.mjs checks them all

This commit is contained in:
yetone
2026-10-01 03:43:39 +08:00
parent 6ba28f67ae
commit 3d94a667f6
3 changed files with 28 additions and 2 deletions
+26
View File
@@ -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" })
})
+1 -1
View File
@@ -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 })
+1 -1
View File
@@ -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",