Wrap non-JSON responses, read timeouts and connection errors in RouterError - #25
Merged
TheCoder30ec4 merged 3 commits intoSep 24, 2026
Conversation
…rError request_json only converted HTTPError and URLError, so a 200 with an HTML body raised json.JSONDecodeError and a read timeout raised TimeoutError. Both escaped the documented `except RouterError:` fallback. Catch them (plus OSError for connection resets) and re-raise as RouterError with the original exception chained.
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.
What does this change?
request_jsonnow catchesTimeoutError,OSError(connection resets) andjson.JSONDecodeError/UnicodeDecodeErrorand re-raises them asRouterErrorwith the original exception chained, so the documentedexcept RouterError:fallback works. Fixes #5.How was it tested?
Added three tests in
tests/test_http.py(non-JSON body, read timeout, connection reset). They fail onmainand pass with this change. Full suite: 68 passed.Checklist
uv run pytestpassesuv run ruff check .anduv run ruff format --check .pass.envcontents in the diff