Repository navigation
fix: accept the API's error field as a string or an object - #7
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Keymint error responses carry
errorin 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-levelmessageand numericcodesince keymint-codebase#227.ApiErrortypederroras an object only, so a string body failed to decode, and the SDK returned a genericAPI error: <raw body>withcode: -1instead of the real message and code.Change
ApiError.UnmarshalJSONaccepts both shapes. An object still fillsErrorDetail(unchanged), a string goes into the newErrorTextfield, andnullor a missingerrorleaves both empty.errorfield, so nothing else changes. The change is additive: no existing field changes.Tests (
contract_test.go)TestApiErrorUnmarshalsErrorFieldShapes: string, object,null, and noerror.TestApiErrorsAcceptStringErrorField: a 403 with a stringerrorthrough the client returns*ApiErrorwithcode: 1, the message, and the status.gofmt -l .is clean.go vet ./...,go build ./...andgo test ./...pass locally. The live suite skipped because no credentials were set.