Skip to content

fix: expose HTTP status code via KeeperHTTPError on JSON-error path (KSM-919) - #65

Merged
stas-schaller merged 1 commit into
release/sdk/golang/core/v1.7.0from
KSM-919-http-status-typed-error
Apr 30, 2026
Merged

fix: expose HTTP status code via KeeperHTTPError on JSON-error path (KSM-919)#65
stas-schaller merged 1 commit into
release/sdk/golang/core/v1.7.0from
KSM-919-http-status-typed-error

Conversation

@stas-schaller

Copy link
Copy Markdown
Contributor

Summary

  • HandleHttpError now returns *KeeperHTTPError on all non-200 paths (JSON-error, raw-body, and non-JSON), making the HTTP status code reachable via errors.As from any caller
  • The JSON-error path previously built the error string without the status code; it now produces "HTTPStatus=N Error: result_code, message=..." matching the existing non-JSON path format
  • The POST Error: wrapper switches from errors.New("POST Error: " + msg) to fmt.Errorf("POST Error: %w", err) so the *KeeperHTTPError stays in the chain

Callers can now branch on status programmatically:

var khe *core.KeeperHTTPError
if errors.As(err, &khe) {
    switch khe.StatusCode {
    case 401, 403:
        // auth failure
    case 429:
        // rate limited
    }
}

Breaking Change

err.Error() on the JSON-error path now includes HTTPStatus=N as a prefix. Code that string-matched "POST Error: Error: access_denied, ..." will no longer match. Migrate to errors.As. See CHANGELOG.md for the migration snippet.

Related Issues

Closes KSM-919
Part of v1.7.0 release (PR #51)

…KSM-919)

HandleHttpError now returns *KeeperHTTPError on all non-200 paths, making
the HTTP status code reachable via errors.As in addition to the error string.
The JSON-error path previously omitted the status code from the caller-returned
error while the non-JSON path already included it; both paths now produce a
consistent "HTTPStatus=N Error: ..." string. The POST Error wrapper uses
fmt.Errorf with %w to preserve the error chain.

Callers can branch on status without grepping stderr:

    var khe *core.KeeperHTTPError
    if errors.As(err, &khe) { ... }

CHANGELOG.md updated with breaking-change callout and migration snippet.
Closes KSM-919
@stas-schaller
stas-schaller merged commit 168d2c0 into release/sdk/golang/core/v1.7.0 Apr 30, 2026
2 checks passed
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