Skip to content

Add HTTP transport layer (step 6)#3

Merged
whitewalls86 merged 2 commits into
masterfrom
step-6-transport
Jun 12, 2026
Merged

Add HTTP transport layer (step 6)#3
whitewalls86 merged 2 commits into
masterfrom
step-6-transport

Conversation

@whitewalls86

Copy link
Copy Markdown
Owner

Summary

  • Adds src/visor/_transport.py with AsyncVisorTransport (httpx.AsyncClient) and SyncVisorTransport (httpx.Client)
  • Both transports inject Authorization: Bearer <key>, support configurable base_url and timeout, and expose a get(path, params) method
  • Shared _handle_response helper maps 4xx/5xx status codes to typed exceptions (ValidationError, AuthError, PaymentRequiredError, ForbiddenError, NotFoundError, RateLimitError, VisorAPIError)
  • _parse_retry_after handles integer seconds and HTTP-date strings from the Retry-After header; returns None for unparseable values
  • httpx.RequestError is caught and re-raised as VisorTransportError
  • Error body parsing uses except ValueError (not broad except Exception) with isinstance guards so malformed envelopes like {"error": "oops"} degrade to unknown_error cleanly

Test 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-After parsing (present / missing / unparseable), non-JSON error body, malformed JSON envelope, and httpx.RequestErrorVisorTransportError
  • ruff check src/ tests/ — no issues
  • ruff format --check src/ tests/ — no issues
  • mypy src/ — no issues

🤖 Generated with Claude Code

whitewalls86 and others added 2 commits June 12, 2026 17:15
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>
@whitewalls86
whitewalls86 merged commit c068f7e into master Jun 12, 2026
2 checks passed
@whitewalls86
whitewalls86 deleted the step-6-transport branch June 12, 2026 22:34
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.

1 participant