Skip to content

feat: expose the API's errorCode on KeyMintApiError - #9

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)

  • KeyMintApiError.ErrorCode (string?, [JsonPropertyName("errorCode")]). It's null when the response has none: older servers, or a non-JSON body (which still gives Code = -1 and HTTP error: …).
  • Message, Code, Status and Error are unchanged.
  • README: new Error Handling section with a switch (result.Error.ErrorCode) example, linking the error code reference.
  • CHANGELOG: "Unreleased / Added" entry. No version bump.

Tests (Tests/ApiContractTests.cs, through ActivateKey)

  • Api_errors_expose_error_code: a 401 with errorCode.
  • Api_errors_without_error_code_leave_it_null: a 429 without it.
  • Non_json_errors_have_no_error_code: a 502 HTML body.

Not run locally. This machine has no .NET SDK, so the build and contract tests rely on this PR's CI (dotnet test --filter "Category!=Live").

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. KeyMintApiError.ErrorCode exposes it; it is null when
a response has none (older servers, non-JSON bodies). Existing
properties and behaviour are unchanged.

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