Repository navigation
fix: accept the API's error field as a string or an object - #8
Merged
Merged
Conversation
Some Keymint error responses send `error` as a string (405, IP-allowlist
403) and others as an object ({code, message}). KeyMintApiError typed it
as an object only, so string bodies failed to deserialise and callers got
a generic "HTTP error: ..." with Code = -1.
A JsonConverter on KeyMintApiError.Error reads either shape; a string is
kept in Error.Message.
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, details}, 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.KeyMintApiError.Errorwas typed as an object only, so a string body threw during deserialisation, andHandleResponsereturned a genericHTTP error: ... Response: <raw body>withCode = -1instead of the real message and code.Change
KeyMintApiErrorDetailsConverteronKeyMintApiError.Error. An object deserialises as before. A string becomesKeyMintApiErrorDetails { Message = "<string>" }(CodeandDetailsstay null).nullor a missingerrorgivesError == null.result.Error.Error?.Messagenow also get the string form.Tests (
Tests/ApiContractTests.cs)Api_errors_accept_a_string_error_field: a 403 with a stringerrorthroughActivateKeyreturns the message,Code = 1andStatus = 403.Api_error_field_deserializes_from_string_or_object: both shapes.Api_error_without_error_field_deserializes: a missingerrorand"error": null.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").