Skip to content

Wrap non-JSON responses, read timeouts and connection errors in RouterError - #25

Merged
TheCoder30ec4 merged 3 commits into
TheCoder30ec4:mainfrom
elliot1377:fix/wrap-json-and-timeout-errors
Sep 24, 2026
Merged

TheCoder30ec4 merged 3 commits into
TheCoder30ec4:mainfrom
elliot1377:fix/wrap-json-and-timeout-errors

Conversation

@elliot1377

Copy link
Copy Markdown
Contributor

What does this change?

request_json now catches TimeoutError, OSError (connection resets) and json.JSONDecodeError/UnicodeDecodeError and re-raises them as RouterError with the original exception chained, so the documented except 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 on main and pass with this change. Full suite: 68 passed.

Checklist

  • uv run pytest passes
  • uv run ruff check . and uv run ruff format --check . pass
  • Tests added or updated for new behavior
  • README / CHANGELOG updated if users will notice the change
  • No API keys or .env contents in the diff

…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.
@TheCoder30ec4
TheCoder30ec4 merged commit d715c73 into TheCoder30ec4:main Sep 24, 2026
8 checks passed
@elliot1377
elliot1377 deleted the fix/wrap-json-and-timeout-errors branch September 25, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-JSON responses and read timeouts escape as JSONDecodeError / TimeoutError instead of RouterError

2 participants