Skip to content

feat: expose the API's errorCode on ApiError - #8

Merged
catsika merged 1 commit into
mainfrom
feat/error-code
Nov 6, 2026
Merged

catsika merged 1 commit into
mainfrom
feat/error-code

Conversation

@catsika

@catsika catsika commented Nov 6, 2026

Copy link
Copy Markdown
Member

Since keymint-codebase#279, every Keymint REST error body has a stable string errorCode (license_invalid_or_forbidden, license_not_found, rate_limited, invalid_request, …) next to message and the numeric code. This PR exposes it so callers can branch on it instead of on message text.

Change (additive)

  • ApiError.ErrorCode string (json:"errorCode,omitempty"). It's empty when the response has none: older servers, or a non-JSON body (which still gives Code: -1 and API error: …).
  • Message, Code, Status, ErrorDetail, ErrorText and Error() are unchanged.
  • README: new Error Handling section with an errors.As + switch apiErr.ErrorCode example, linking the error code reference.

Tests (TestApiErrorsExposeErrorCode in contract_test.go, through the client)

  • with errorCode
  • with errorCode plus the legacy error object
  • without errorCode
  • a non-JSON body

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

Every Keymint REST error now carries a stable string errorCode
(e.g. license_invalid_or_forbidden, rate_limited) next to message and
the numeric code. ApiError.ErrorCode exposes it; it is empty when a
response has none (older servers, non-JSON bodies). Existing fields and
behaviour are unchanged.

README: new Error Handling section that branches on ErrorCode instead
of message text.
@catsika
catsika merged commit 7333026 into main Nov 6, 2026
2 checks passed
@catsika
catsika deleted the feat/error-code branch November 6, 2026 16:21
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