Skip to content

fix: accept the API's error field as a string or an object - #7

Merged
catsika merged 1 commit into
mainfrom
fix/error-field-string-or-object
Nov 5, 2026
Merged

catsika merged 1 commit into
mainfrom
fix/error-field-string-or-object

Conversation

@catsika

@catsika catsika commented Nov 5, 2026

Copy link
Copy Markdown
Member

Keymint error responses carry error in two shapes: an object ({code, message}, e.g. rate limits and validation) and a plain string (e.g. the 405 "Method not allowed" and the IP-allowlist 403). Every error also has a top-level message and numeric code since keymint-codebase#227. ApiError typed error as an object only, so a string body failed to decode, and the SDK returned a generic API error: <raw body> with code: -1 instead of the real message and code.

Change

  • ApiError.UnmarshalJSON accepts both shapes. An object still fills ErrorDetail (unchanged), a string goes into the new ErrorText field, and null or a missing error leaves both empty.
  • No other types have an error field, so nothing else changes. The change is additive: no existing field changes.

Tests (contract_test.go)

  • TestApiErrorUnmarshalsErrorFieldShapes: string, object, null, and no error.
  • TestApiErrorsAcceptStringErrorField: a 403 with a string error through the client returns *ApiError with code: 1, the message, and the status.

gofmt -l . is clean. go vet ./..., go build ./... and go test ./... pass locally. The live suite skipped because no credentials were set.

Some Keymint error responses send `error` as a string (405, IP-allowlist
403) and others as an object ({code, message}). ApiError typed it as an
object only, so string bodies failed to decode and surfaced as a generic
"API error: ..." with code -1.

ApiError now has a custom UnmarshalJSON: an object still fills
ErrorDetail, and a string is kept in the new ErrorText field.
@catsika
catsika merged commit 9c1099b into main Nov 5, 2026
2 checks passed
@catsika
catsika deleted the fix/error-field-string-or-object branch November 5, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant