Repository navigation
fix: raise SDK errors for unexpected HTTP error bodies - #95
Draft
Kayvan-Zahiri wants to merge 1 commit into
Draft
Kayvan-Zahiri wants to merge 1 commit into
Kayvan-Zahiri wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
An HTTP 502 HTML/plain-text response currently raises
JSONDecodeErrorfromsearch()/async_search(), hiding the SDK error contract. JSON error responses without the expected object envelope can instead fall through into success-response parsing, or raiseTypeError/AttributeErrorfor null/scalar error values.Catch JSON decoding failures and validate the error-envelope shape before accessing it. Unexpected bodies raise the existing
UnknownErrorwith the HTTP status and original response text. Valid structured errors continue through the existing status/code-specific mapping unchanged. The shared helper covers both sync and async requests, including their existing payment-retry path.Added 18 public-client regression cases covering HTML, empty/plain-text bodies, JSON null/arrays, missing error envelopes, null/string error values, and a valid unknown-error control. Sixteen fail against the original implementation; two controls pass.
Validation (Python 3.13, locked development dependencies):
make lint typecheck testpasses, including the new tracked regression file in pre-commit checks.uv buildcreates the wheel and source distribution.git diff --checkpass.Responses are mocked at the HTTP request boundary. No live searches, account operations, or payment signing/settlement were performed. No package version or release configuration changes.