Add HTTP transport layer (step 6)#3
Merged
Merged
Conversation
Implements _transport.py with AsyncVisorTransport and SyncVisorTransport backed by httpx. Shared _handle_response helper maps 4xx/5xx status codes to typed exceptions; _parse_retry_after handles integer and HTTP-date Retry-After values. 28 tests cover both transports via respx mocks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces broad `except Exception` with `except ValueError` for JSON
decode failures and adds isinstance guards so a malformed envelope like
{"error": "oops"} surfaces as unknown_error instead of masking the
AttributeError. Adds a regression test for the malformed envelope case.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
src/visor/_transport.pywithAsyncVisorTransport(httpx.AsyncClient) andSyncVisorTransport(httpx.Client)Authorization: Bearer <key>, support configurablebase_urlandtimeout, and expose aget(path, params)method_handle_responsehelper maps 4xx/5xx status codes to typed exceptions (ValidationError,AuthError,PaymentRequiredError,ForbiddenError,NotFoundError,RateLimitError,VisorAPIError)_parse_retry_afterhandles integer seconds and HTTP-date strings from theRetry-Afterheader; returnsNonefor unparseable valueshttpx.RequestErroris caught and re-raised asVisorTransportErrorexcept ValueError(not broadexcept Exception) withisinstanceguards so malformed envelopes like{"error": "oops"}degrade tounknown_errorcleanlyTest plan
pytest tests/test_transport.py— 29 tests covering both transports: auth header, base URL + path composition, query params, success JSON return, all 7 status→exception mappings,Retry-Afterparsing (present / missing / unparseable), non-JSON error body, malformed JSON envelope, andhttpx.RequestError→VisorTransportErrorruff check src/ tests/— no issuesruff format --check src/ tests/— no issuesmypy src/— no issues🤖 Generated with Claude Code