Files
magpie/internal/provider/api_error_fields_test.go
T
yetone db9048829b provider: a vendor's 400 whose message is only "Bad Request" shows its type, code and param (FjTxw0Mz8wxBuye on X)
Codex on a Team account (gpt-6.1-sol, high reasoning) showed a bare
"Codex: Bad Request" with nothing of what the vendor refused. apiError took
the error object's message alone; when that message is only an HTTP
status's text, the error's own type, code and param now follow it.
Any message with words of its own is shown as before.

This does not find why that account is refused: no Team account was
available, and a Pro account takes the same request (gpt-6.1-sol, high,
a tool call, HTTP and socket). The next report shows the vendor's field.

Run: new TestAPIErrorBareStatusMessageGivesItsFields (red on the old
apiError, green after), internal/provider and internal/gateway whole at
this tree, go vet darwin, windows and linux nogui for provider, gofmt.
Not tried: a Team account; the GUI tests (no GUI file touched).
2026-11-12 17:03:53 +08:00

23 lines
1.1 KiB
Go

package provider
import "testing"
// A 400 whose message is only the status's text ("Bad Request", Codex on a
// Team account, FjTxw0Mz8wxBuye on X) says what it refused in its type,
// code and param, which the user is shown after it; a message with words
// of its own is shown as it is.
func TestAPIErrorBareStatusMessageGivesItsFields(t *testing.T) {
for _, c := range []struct{ body, want string }{
{`{"error":{"message":"Bad Request","type":"invalid_request_error","code":"invalid_value","param":"input[3].content"}}`,
"Bad Request (invalid_request_error, invalid_value, input[3].content)"},
{`{"error":{"message":"Bad Request","type":"invalid_request_error","code":null,"param":null}}`,
"Bad Request (invalid_request_error)"},
{`{"error":{"message":"Bad Request"}}`, "Bad Request"},
{`{"error":{"message":"Unsupported parameter: foo","type":"invalid_request_error","param":"foo"}}`, "Unsupported parameter: foo"},
} {
if got := APIError([]byte(c.body), "400 Bad Request"); got != c.want {
t.Errorf("%s\n got %q\nwant %q", c.body, got, c.want)
}
}
}