Skip to content

feat: expose the API's errorCode on KeyMintApiError - #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)

  • KeyMintApiError.errorCode?: string.
  • handleError copies errorCode onto the rejected error only when the body has a string errorCode. Errors without one keep exactly the previous object shape ({ message, code, status }), so existing deepEqual-style checks still hold.
  • message, code and status are unchanged.
  • README: new Error Handling section with a switch (error.errorCode) example, linking the error code reference.
  • CHANGELOG: "Unreleased / Added" entry. No version bump.

Tests (tests/contracts.test.cjs)

  • The nested-error mock now sends errorCode: 'conflict', code: 2, and "workspace" instead of the old "team" wording, and asserts errorCode.
  • New tests:
    • an error with errorCode (full shape)
    • an error without it (no errorCode key)
    • a non-JSON 502 (code: -1, no errorCode)

npm test passes locally (13 contract + 52 offline tests) and npm run lint is clean. The live suite was not run.

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. handleError copies it onto the rejected error when the
body has one; errors without it keep exactly the previous shape.

Tests: the nested-error mock now sends errorCode (and "workspace" for
the old "team" wording) and asserts it; new tests cover an error with
errorCode, one without, and a non-JSON body.

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