gateway: Qoder's queue (code 10605) is a 503 with Retry-After for users still on the built-in, not "sign in again" (plugins #98)
What changed: qoderFailure (internal/gateway/qoder.go) read every 401/403
as "Qoder: the sign-in lapsed — sign in again". It now reads Qoder's own
code first, whatever the HTTP status, the way Qoder.app's client does
(the QoderErrorCode table in its qoder-agent-sdk worker,
qoder-worker-runtime.obf.mjs) and as @magpie-community/opencode-qoder-auth
0.2.14 does (plugins f573cfd):
- 10605, or a queue state (in "queue" or in the message as JSON) with
isQueued true or serviceAvailable false: 503 "Qoder is busy for
<model> (this plan's queue: <tier>); try again in <n>s", with
Retry-After from retryAfterSeconds rounded up (30s when absent).
- 110, 112-119, 122 (usage or credits used up): 429.
- 406, 416, 430, 80411, 80412, 100400, 100401, 100403 (refusals of the
request; Qoder's table has no 100402): 400 with Qoder's words.
- 105 or no code on a 401/403: the 401 "sign in again" as before.
Both the HTTP status path (askQoder) and the in-stream statusCodeValue
path (decodeQoder) go through it. Event gets a Wait field for a KError,
and relayStatus's fail and serveQoder's first-round failure send it as
Retry-After (retryAfterOn); askQoderWait is askQoder that also returns
the wait, and askQoder (the round searchRounds uses) wraps it. Zed and
Command Code share relayStatus and never set Wait, so they are
unchanged.
Why: a real Qoder trial account had every chat answered
403 {"code":"10605",...} (Qoder's model queue) and was told to sign in
again, which can't help. The plugin was fixed in 0.2.14 for moved users;
this is the same fix for users still signed in through the built-in. The
built-in never marked an account lapsed from a refused chat (only from a
refused refresh, provider/qoder.go), and now a 10605 doesn't even return
the 401: the gateway's busy() reads the 503 as busy (failOther), so a
group asks it again after the pause, no shorter than its Retry-After
(noteBusy/retryAfter), and the agent gets the Retry-After too.
Run:
- New tests in internal/gateway/qoder_busy_test.go, the fixture
testdata/qoder_queued_10605.json taken byte for byte from plugins #98:
TestQoderQueuedIsBusy (serveQoder, HTTP 403 and in-stream 403, stream
and not: 503, Retry-After 30, the busy words, no "sign in", busy() true,
retryAfter 30s), TestQoderQueueWait, TestQoderErrorCodes. With the old
401/403 rule put back at the top of qoderFailure all three FAIL
("got 401 ... want 503"); with retryAfterOn made a no-op
TestQoderQueuedIsBusy FAILs on Retry-After "" in both subtests. Restored,
they pass.
- go test -tags nogui ./internal/provider ok (458s). go test -tags nogui
-timeout 40m ./internal/gateway (the default 10m ran out under the
machine's load): every test passed except TestCodexHeardWithinItsIdleTimeout,
which failed with the body #1800 already describes (Codex got member
a's server_is_overloaded under load); it passes 10 of 10 alone
(-count=10) and is on the Codex passthrough path, which this doesn't
touch. Noted on #1800.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./... ok; go build, GOOS=linux go build -tags nogui,
GOOS=windows go build ok.
- Not run: the rest of go test ./... (only the two packages touched);
a real 10605 through the built-in (the queue had reopened when the
plugin shipped); no Qoder parity test exists in
internal/gateway/plugin_*_test.go to extend.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The APIs are close cousins; everything below is the shape they have
|
||||
@@ -286,6 +287,10 @@ type Event struct {
|
||||
// StopDetails: Anthropic's stop_details, what its classifier said of
|
||||
// a refusal (#1768), carried to the client as it came
|
||||
StopDetails json.RawMessage
|
||||
|
||||
// Wait: for KError, how long the vendor said to wait before asking
|
||||
// again, when it said; sent on as Retry-After
|
||||
Wait time.Duration
|
||||
}
|
||||
|
||||
// Usage counts tokens.
|
||||
|
||||
+105
-21
@@ -17,9 +17,11 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -83,8 +85,9 @@ func (s *Server) serveQoder(w http.ResponseWriter, r *http.Request, from provide
|
||||
q, tool = ©, search.Name
|
||||
}
|
||||
}
|
||||
events, status, msg := ask(ctx, q)
|
||||
events, status, msg, wait := s.askQoderWait(p.Account.Agent, model, p.Account.User)(ctx, q)
|
||||
if events == nil {
|
||||
retryAfterOn(w, wait)
|
||||
return writeError(w, from, status, msg), msg
|
||||
}
|
||||
if tool != "" {
|
||||
@@ -115,6 +118,7 @@ func relayStatus(w http.ResponseWriter, from provider.Protocol, name string, req
|
||||
if code < 400 || code > 599 {
|
||||
code = 502
|
||||
}
|
||||
retryAfterOn(w, ev.Wait)
|
||||
return writeError(w, from, code, ev.Text), ev.Text
|
||||
}
|
||||
if req.Stream {
|
||||
@@ -172,10 +176,30 @@ func relayStatus(w http.ResponseWriter, from provider.Protocol, name string, req
|
||||
return 200, ""
|
||||
}
|
||||
|
||||
// retryAfterOn sends, with an error about to be written to w, how long
|
||||
// the vendor said to wait before asking again, when it said: the agent
|
||||
// reads it, and so does the gateway's busy handling (noteBusy).
|
||||
func retryAfterOn(w http.ResponseWriter, wait time.Duration) {
|
||||
if wait > 0 {
|
||||
w.Header().Set("Retry-After", strconv.Itoa(int(math.Ceil(wait.Seconds()))))
|
||||
}
|
||||
}
|
||||
|
||||
// askQoder is a round for Qoder's API, on the site agent ("qoder" or
|
||||
// "qoder-cn") names.
|
||||
func (s *Server) askQoder(agent, model, user string) round {
|
||||
ask := s.askQoderWait(agent, model, user)
|
||||
return func(ctx context.Context, req *Request) (<-chan Event, int, string) {
|
||||
events, status, msg, _ := ask(ctx, req)
|
||||
return events, status, msg
|
||||
}
|
||||
}
|
||||
|
||||
// askQoderWait is askQoder that also says, of a failure, how long Qoder
|
||||
// said to wait before asking again (its queue's retryAfterSeconds), for
|
||||
// serveQoder to send as Retry-After.
|
||||
func (s *Server) askQoderWait(agent, model, user string) func(ctx context.Context, req *Request) (<-chan Event, int, string, time.Duration) {
|
||||
return func(ctx context.Context, req *Request) (<-chan Event, int, string, time.Duration) {
|
||||
cred, err := qoderAuth(ctx, agent, user)
|
||||
if err != nil {
|
||||
// only a sign-in that is gone asks the agent to log in again;
|
||||
@@ -184,15 +208,15 @@ func (s *Server) askQoder(agent, model, user string) round {
|
||||
if errors.Is(err, provider.ErrQoderSignIn) {
|
||||
status = 401
|
||||
}
|
||||
return nil, status, "Qoder: " + err.Error()
|
||||
return nil, status, "Qoder: " + err.Error(), 0
|
||||
}
|
||||
config, err := qoderModel(ctx, agent, user, model)
|
||||
if err != nil {
|
||||
return nil, 400, err.Error()
|
||||
return nil, 400, err.Error(), 0
|
||||
}
|
||||
plain, err := qoderChatBody(req, config)
|
||||
if err != nil {
|
||||
return nil, 500, "Qoder: " + err.Error()
|
||||
return nil, 500, "Qoder: " + err.Error(), 0
|
||||
}
|
||||
wire := qoder.EncodeRequestBody(plain)
|
||||
ts := time.Now().Unix()
|
||||
@@ -200,11 +224,11 @@ func (s *Server) askQoder(agent, model, user string) round {
|
||||
headers, err := qoder.BuildCosyHeaders(chat, &qoder.User{UID: cred.UID, Token: cred.Token,
|
||||
Name: cred.Name, Email: cred.Email, MachineID: cred.MachineID}, wire, ts)
|
||||
if err != nil {
|
||||
return nil, 500, "Qoder: " + err.Error()
|
||||
return nil, 500, "Qoder: " + err.Error(), 0
|
||||
}
|
||||
hr, err := http.NewRequestWithContext(ctx, http.MethodPost, chat, strings.NewReader(wire))
|
||||
if err != nil {
|
||||
return nil, 500, "Qoder: " + err.Error()
|
||||
return nil, 500, "Qoder: " + err.Error(), 0
|
||||
}
|
||||
for k, v := range headers {
|
||||
hr.Header.Set(k, v)
|
||||
@@ -216,46 +240,106 @@ func (s *Server) askQoder(agent, model, user string) round {
|
||||
hr.Header.Set("X-Model-Source", config.Source)
|
||||
res, err := s.client.Do(hr)
|
||||
if err != nil {
|
||||
return nil, 502, "Qoder: " + err.Error()
|
||||
return nil, 502, "Qoder: " + err.Error(), 0
|
||||
}
|
||||
res = notAnAPIReply(res, "") // a web page served 200 (#1012)
|
||||
if res.StatusCode/100 != 2 {
|
||||
b, _ := io.ReadAll(io.LimitReader(res.Body, 1<<20))
|
||||
res.Body.Close()
|
||||
status, msg := qoderFailure(res.StatusCode, b)
|
||||
return nil, status, msg
|
||||
status, msg, wait := qoderFailure(res.StatusCode, b)
|
||||
return nil, status, msg, wait
|
||||
}
|
||||
events := make(chan Event, 32)
|
||||
go decodeQoder(ctx, res, events, model)
|
||||
return events, 0, ""
|
||||
return events, 0, "", 0
|
||||
}
|
||||
}
|
||||
|
||||
// qoderFailure maps a bad upstream status to magpie's status and message.
|
||||
func qoderFailure(status int, body []byte) (int, string) {
|
||||
// Qoder's own error codes, read as Qoder's client reads them (the
|
||||
// QoderErrorCode table in Qoder.app's qoder-agent-sdk worker), and as the
|
||||
// plugin does (@magpie-community/opencode-qoder-auth 0.2.14): only 105
|
||||
// (loginExpired) is a lapsed sign-in there, so a 401/403 that carries
|
||||
// another code isn't one here either (plugins #98: the model's queue,
|
||||
// 10605, came as a 403 and read as "sign in again").
|
||||
const qoderQueued = "10605"
|
||||
|
||||
var (
|
||||
// the codes Qoder's client counts as a plan's usage or credits used up
|
||||
qoderQuotaCodes = map[string]bool{"110": true, "112": true, "113": true, "114": true, "115": true,
|
||||
"116": true, "117": true, "118": true, "119": true, "122": true}
|
||||
// refusals of this request, not of the account: sensitive content,
|
||||
// not supported, input too long, too many media, a custom model's
|
||||
// service (Qoder's table has no 100402)
|
||||
qoderRequestCodes = map[string]bool{"406": true, "416": true, "430": true, "80411": true, "80412": true,
|
||||
"100400": true, "100401": true, "100403": true}
|
||||
)
|
||||
|
||||
// qoderBusyWait is how long a queued request waits when Qoder names no time.
|
||||
const qoderBusyWait = 30 * time.Second
|
||||
|
||||
// qoderFailure maps a bad upstream status to magpie's status and message,
|
||||
// and how long Qoder said to wait before asking again (0 when it didn't).
|
||||
// Qoder's code in the body says what the failure is, whatever the status.
|
||||
func qoderFailure(status int, body []byte) (int, string, time.Duration) {
|
||||
if status < 400 || status > 599 {
|
||||
status = 502
|
||||
}
|
||||
msg := strings.TrimSpace(string(body))
|
||||
var code string
|
||||
var queue gjson.Result
|
||||
if gjson.ValidBytes(body) {
|
||||
if m := gjson.GetBytes(body, "message").String(); m != "" {
|
||||
code = gjson.GetBytes(body, "code").String()
|
||||
m := gjson.GetBytes(body, "message").String()
|
||||
if m != "" {
|
||||
msg = m
|
||||
}
|
||||
// the model vendor's own reason, e.g. an effort the model refuses
|
||||
if d := gjson.Get(gjson.GetBytes(body, "details").String(), "error.message").String(); d != "" {
|
||||
msg += ": " + d
|
||||
}
|
||||
// the queue's state: a field, or the message itself as JSON
|
||||
if q := gjson.GetBytes(body, "queue"); q.IsObject() {
|
||||
queue = q
|
||||
} else if q := gjson.Parse(m); strings.HasPrefix(strings.TrimSpace(m), "{") && q.IsObject() &&
|
||||
(q.Get("isQueued").Exists() || q.Get("serviceAvailable").Exists() || q.Get("retryAfterSeconds").Exists()) {
|
||||
queue = q
|
||||
}
|
||||
}
|
||||
if msg == "" {
|
||||
msg = http.StatusText(status)
|
||||
}
|
||||
switch {
|
||||
case status == http.StatusUnauthorized || status == http.StatusForbidden:
|
||||
return 401, "Qoder: the sign-in lapsed — sign in again"
|
||||
case status == http.StatusTooManyRequests || strings.Contains(strings.ToLower(msg), "quota"):
|
||||
return 429, "usage limit reached: " + msg
|
||||
// Qoder's queue for the model: busy for now, with when to ask again.
|
||||
// The sign-in is fine (the same token reads the models and the usage),
|
||||
// so it is a 503 with Retry-After, which the gateway counts as busy and
|
||||
// asks again after, and never "sign in again"
|
||||
if code == qoderQueued || queue.Get("isQueued").Type == gjson.True || queue.Get("serviceAvailable").Type == gjson.False {
|
||||
wait := qoderBusyWait
|
||||
if n := queue.Get("retryAfterSeconds").Float(); n > 0 {
|
||||
wait = time.Duration(math.Ceil(n)) * time.Second
|
||||
}
|
||||
what := "is busy"
|
||||
if queue.Get("isQueued").Type == gjson.True {
|
||||
what = "queued the request"
|
||||
}
|
||||
if k := queue.Get("modelKey").String(); k != "" {
|
||||
what += " for " + k
|
||||
}
|
||||
if t := queue.Get("queueType").String(); t != "" {
|
||||
what += " (this plan's queue: " + t + ")"
|
||||
}
|
||||
return 503, fmt.Sprintf("Qoder %s; try again in %ds", what, int(wait/time.Second)), wait
|
||||
}
|
||||
return status, "Qoder: " + msg
|
||||
switch {
|
||||
case qoderQuotaCodes[code]:
|
||||
return 429, "usage limit reached: " + msg, 0
|
||||
case qoderRequestCodes[code]:
|
||||
return 400, fmt.Sprintf("Qoder refused the request (%s): %s", code, msg), 0
|
||||
case status == http.StatusUnauthorized || status == http.StatusForbidden:
|
||||
return 401, "Qoder: the sign-in lapsed — sign in again", 0
|
||||
case status == http.StatusTooManyRequests || strings.Contains(strings.ToLower(msg), "quota"):
|
||||
return 429, "usage limit reached: " + msg, 0
|
||||
}
|
||||
return status, "Qoder: " + msg, 0
|
||||
}
|
||||
|
||||
// qoderChatBody is the plaintext JSON Qoder's agent_chat_generation takes,
|
||||
@@ -507,8 +591,8 @@ func decodeQoder(ctx context.Context, res *http.Response, out chan<- Event, mode
|
||||
if len(data) == 0 {
|
||||
data = []byte(payload)
|
||||
}
|
||||
code, msg := qoderFailure(int(status.Int()), data)
|
||||
send(Event{Kind: KError, Status: code, Text: msg})
|
||||
code, msg, wait := qoderFailure(int(status.Int()), data)
|
||||
send(Event{Kind: KError, Status: code, Text: msg, Wait: wait})
|
||||
return
|
||||
}
|
||||
if inner == "" || !json.Valid([]byte(inner)) {
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/qoder"
|
||||
)
|
||||
|
||||
// plugins #98: Qoder's queue refusing a chat (code 10605) is Qoder being
|
||||
// busy for the plan, not a lapsed sign-in. The body is the one Qoder gave a
|
||||
// real trial account on 2026-10-12, byte for byte from the issue
|
||||
// (testdata/qoder_queued_10605.json). The other codes are read as Qoder's
|
||||
// own client reads them (QoderErrorCode in Qoder.app's qoder-agent-sdk
|
||||
// worker), as the plugin reads them since 0.2.14: only 105 is loginExpired.
|
||||
|
||||
func qoderQueuedBody(t *testing.T) string {
|
||||
t.Helper()
|
||||
b, err := os.ReadFile("testdata/qoder_queued_10605.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return strings.TrimSpace(string(b))
|
||||
}
|
||||
|
||||
// qoderRefusing stands in for api3.qoder.sh answering every chat with
|
||||
// status and body, as qoderUpstream does with a stream.
|
||||
func qoderRefusing(t *testing.T, status int, body string) {
|
||||
t.Helper()
|
||||
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
io.Copy(io.Discard, r.Body)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
io.WriteString(w, body)
|
||||
}))
|
||||
auth, url, model := qoderAuth, qoderURL, qoderModel
|
||||
qoderAuth = func(context.Context, string, string) (*qoder.Credential, error) {
|
||||
return &qoder.Credential{UID: "uid-test", Token: "jt-test", MachineID: "machine-test"}, nil
|
||||
}
|
||||
qoderModel = func(context.Context, string, string, string) (qoder.ModelInfo, error) { return testQoderModel(t), nil }
|
||||
qoderURL = func(*qoder.Credential) string { return up.URL }
|
||||
t.Cleanup(func() { up.Close(); qoderAuth, qoderURL, qoderModel = auth, url, model })
|
||||
}
|
||||
|
||||
const qoderBusyWant = "Qoder is busy for efficient (this plan's queue: p3); try again in 30s"
|
||||
|
||||
// serveQoderOnce sends one chat through serveQoder, as the gateway does.
|
||||
func serveQoderOnce(t *testing.T, stream bool) *httptest.ResponseRecorder {
|
||||
t.Helper()
|
||||
body := `{"model":"qfmodel","stream":` + map[bool]string{true: "true", false: "false"}[stream] + `,"messages":[{"role":"user","content":"hi"}]}`
|
||||
w := httptest.NewRecorder()
|
||||
r := httptest.NewRequest("POST", "/", strings.NewReader(body))
|
||||
var u Usage
|
||||
s := New()
|
||||
s.serveQoder(w, r, provider.Chat, provider.Provider{Account: &provider.Account{Agent: "qoder", User: "one@x"}}, "qfmodel", []byte(body), &u)
|
||||
return w
|
||||
}
|
||||
|
||||
// checkQoderBusy: a 503 with Qoder's own wait as Retry-After, worded as
|
||||
// busy, never "sign in again" — and the gateway's busy handling takes it
|
||||
// as busy (asked again after the pause) and waits its Retry-After.
|
||||
func checkQoderBusy(t *testing.T, w *httptest.ResponseRecorder) {
|
||||
t.Helper()
|
||||
msg := gjson.Get(w.Body.String(), "error.message").String()
|
||||
if w.Code != 503 || w.Header().Get("Retry-After") != "30" || msg != qoderBusyWant {
|
||||
t.Fatalf("got %d Retry-After %q %q, want 503 Retry-After 30 %q", w.Code, w.Header().Get("Retry-After"), msg, qoderBusyWant)
|
||||
}
|
||||
if strings.Contains(strings.ToLower(w.Body.String()), "sign in") {
|
||||
t.Fatalf("a queued request asks to sign in again: %s", w.Body.String())
|
||||
}
|
||||
if !busy(w.Code, w.Body.Bytes()) {
|
||||
t.Fatalf("the gateway doesn't take it as busy (failure %q): %s", failure(w.Code, w.Body.Bytes()), w.Body.String())
|
||||
}
|
||||
if d := retryAfter(w.Header(), time.Now()); d != 30*time.Second {
|
||||
t.Fatalf("the gateway waits %s, want Qoder's 30s", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQoderQueuedIsBusy(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
||||
queued := qoderQueuedBody(t)
|
||||
|
||||
t.Run("http 403", func(t *testing.T) {
|
||||
qoderRefusing(t, 403, queued)
|
||||
for _, stream := range []bool{false, true} {
|
||||
checkQoderBusy(t, serveQoderOnce(t, stream))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("in the stream before any answer", func(t *testing.T) {
|
||||
env, _ := json.Marshal(map[string]any{"headers": map[string]any{}, "body": queued, "statusCodeValue": 403, "statusCode": "FORBIDDEN"})
|
||||
done := qoderUpstream(t, []string{string(env)})
|
||||
defer done()
|
||||
for _, stream := range []bool{false, true} {
|
||||
checkQoderBusy(t, serveQoderOnce(t, stream))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// The queue's own wait is used, rounded up; a queued request says so; with
|
||||
// no wait it is 30s; and a queue state under another status is the same.
|
||||
func TestQoderQueueWait(t *testing.T) {
|
||||
q := func(status int, code string, queue map[string]any) (int, string, time.Duration) {
|
||||
m, _ := json.Marshal(queue)
|
||||
b, _ := json.Marshal(map[string]any{"code": code, "message": string(m)})
|
||||
return qoderFailure(status, b)
|
||||
}
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
status int
|
||||
code string
|
||||
queue map[string]any
|
||||
want string
|
||||
wait time.Duration
|
||||
}{
|
||||
{"queued", 403, "10605", map[string]any{"isQueued": true, "modelKey": "ultimate", "retryAfterSeconds": 12.2}, "Qoder queued the request for ultimate; try again in 13s", 13 * time.Second},
|
||||
{"no wait", 403, "10605", map[string]any{"serviceAvailable": false}, "Qoder is busy; try again in 30s", 30 * time.Second},
|
||||
{"queue state on a 429, no code", 429, "", map[string]any{"serviceAvailable": false, "retryAfterSeconds": 5}, "Qoder is busy; try again in 5s", 5 * time.Second},
|
||||
} {
|
||||
status, msg, wait := q(tt.status, tt.code, tt.queue)
|
||||
if status != 503 || msg != tt.want || wait != tt.wait {
|
||||
t.Errorf("%s: %d %q %s, want 503 %q %s", tt.name, status, msg, wait, tt.want, tt.wait)
|
||||
}
|
||||
}
|
||||
// the code alone, the message plain text; a numeric code too
|
||||
for _, b := range []string{`{"code":"10605","message":"busy"}`, `{"code":10605,"message":"busy"}`} {
|
||||
if status, _, wait := qoderFailure(403, []byte(b)); status != 503 || wait != 30*time.Second {
|
||||
t.Errorf("%s: %d %s, want 503 30s", b, status, wait)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Qoder's other codes on a 401/403 aren't a lapsed sign-in either; 105
|
||||
// and no code are.
|
||||
func TestQoderErrorCodes(t *testing.T) {
|
||||
f := func(status int, code, message string) (int, string, time.Duration) {
|
||||
b, _ := json.Marshal(map[string]any{"code": code, "message": message})
|
||||
return qoderFailure(status, b)
|
||||
}
|
||||
for _, status := range []int{401, 403} {
|
||||
for _, code := range []string{"110", "112", "113", "114", "115", "116", "117", "118", "119", "122"} {
|
||||
if got, msg, _ := f(status, code, "credits used up"); got != 429 || msg != "usage limit reached: credits used up" {
|
||||
t.Errorf("%d code %s: %d %q, want 429", status, code, got, msg)
|
||||
}
|
||||
}
|
||||
for _, code := range []string{"406", "416", "430", "80411", "80412", "100400", "100401", "100403"} {
|
||||
if got, msg, _ := f(status, code, "no"); got != 400 || msg != "Qoder refused the request ("+code+"): no" {
|
||||
t.Errorf("%d code %s: %d %q, want 400", status, code, got, msg)
|
||||
}
|
||||
}
|
||||
for _, b := range []string{`{"code":"105","message":"login expired"}`, `{"message":"forbidden"}`, ``} {
|
||||
if got, msg, wait := qoderFailure(status, []byte(b)); got != 401 || msg != "Qoder: the sign-in lapsed — sign in again" || wait != 0 {
|
||||
t.Errorf("%d %s: %d %q %s, want the 401", status, b, got, msg, wait)
|
||||
}
|
||||
}
|
||||
}
|
||||
// a quota without a code reads as before
|
||||
if got, _, _ := qoderFailure(429, []byte(`{"message":"额度已耗尽"}`)); got != 429 {
|
||||
t.Errorf("a 429: %d", got)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"code":"10605","message":"{\"isQueued\":false,\"modelKey\":\"efficient\",\"queueCount\":0,\"queueType\":\"p3\",\"retryAfterSeconds\":30,\"serviceAvailable\":false,\"waitTime\":0}"}
|
||||
Reference in New Issue
Block a user