feat: add bounded HTTP retries and structured exceptions - #259
Merged
Conversation
Add bounded urllib3 Retry adapters for library-created Sessions and introduce structured transport, timeout, HTTP, and decode exceptions while preserving 4xx empty-result compatibility. Co-authored-by: Matthew Spah <[email protected]>
Remove an unused local-server fixture dependency from the decode no-retry test. Co-authored-by: Matthew Spah <[email protected]>
Mattsface
marked this pull request as ready for review
August 1, 2026 07:33
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.
Why
Version 0.8.0 needs bounded recovery from temporary MLB/network failures and structured exceptions so callers can distinguish transport, timeout, HTTP, and decode failures while keeping the existing synchronous API and 4xx empty-result compatibility.
Depends on merged PR #258 (shared Sessions and timeouts). Issue 3 merge commit
6c4db03is in this branch’s history.What
Retryvia RequestsHTTPAdapter):total=3,connect=3,read=2,status=3,backoff_factor=0.5respect_retry_after_header=Trueraise_on_status=Falseso the final response returns toMlbDataAdapterfor package rulesallowed_methods=frozenset({"GET"})) so unsafe methods are never retried429,500,502,503,504(plus connection/read failures via Retry)400,401,403,404, invalid JSON, Pydantic/parsing errorsraise_on_status=Falsekeeps urllib3 from raising status-retry exceptions to callers; the adapter applies compatibility rulesMlbResult(data={})(noMlbHttpErrorfor 429)TheMlbStatsApiExceptionMlbTransportError→MlbTimeoutErrorMlbHttpError(status_code,reason,url)MlbDecodeError"Request failed","Bad JSON in response","500: Internal Server Error"__cause__mlbstatsapi/__init__.pyTests
Retry behavior is proven with an in-process
ThreadingHTTPServeron127.0.0.1(no public network).Retry.sleepis patched to avoid real backoff waits.Risk and impact
TheMlbStatsApiExceptioncontinue to workMlbHttpError/ empty 4xx results after the attempt budget