feat: capture HTTP Retry-After header in Error::retry_delay() for HttpStatus errors #21

Closed
opened 2026-10-28 08:44:56 +00:00 by andreban · 0 comments
Owner

Problem

Error::retry_delay() (added in #19 / #20) only reads the google.rpc.RetryInfo detail in a Vertex JSON error body. When a 429/503 arrives with a body that isn't Vertex JSON (for example from a proxy or gateway), the client returns Error::HttpStatus { status, body }. Response headers are thrown away when that error is built (src/client.rs, the non-JSON error path), so a Retry-After header is lost. is_retryable() returns true, but retry_delay() returns None, so callers fall back to their own backoff and may retry too early.

Proposed Changes

  1. src/error.rs: add a retry_after: Option<std::time::Duration> field to Error::HttpStatus (breaking changes are acceptable).
  2. src/client.rs: wherever Error::HttpStatus is built, read the Retry-After header before the body is consumed. Support the delay-seconds form (Retry-After: 30); the HTTP-date form is optional.
  3. Error::retry_delay(): return retry_after for HttpStatus.
    • Optionally, for VertexError, fall back to the header when the body has no RetryInfo.
  4. Tests: use the existing local mock HTTP server tests in src/client_tests.rs to cover a 429 with Retry-After: 30 and a non-JSON body, a missing or invalid header, and retry_delay() for each case.
## Problem `Error::retry_delay()` (added in #19 / #20) only reads the `google.rpc.RetryInfo` detail in a Vertex JSON error body. When a 429/503 arrives with a body that isn't Vertex JSON (for example from a proxy or gateway), the client returns `Error::HttpStatus { status, body }`. Response headers are thrown away when that error is built (`src/client.rs`, the non-JSON error path), so a `Retry-After` header is lost. `is_retryable()` returns `true`, but `retry_delay()` returns `None`, so callers fall back to their own backoff and may retry too early. ## Proposed Changes 1. `src/error.rs`: add a `retry_after: Option<std::time::Duration>` field to `Error::HttpStatus` (breaking changes are acceptable). 2. `src/client.rs`: wherever `Error::HttpStatus` is built, read the `Retry-After` header before the body is consumed. Support the delay-seconds form (`Retry-After: 30`); the HTTP-date form is optional. 3. `Error::retry_delay()`: return `retry_after` for `HttpStatus`. - Optionally, for `VertexError`, fall back to the header when the body has no `RetryInfo`. 4. **Tests**: use the existing local mock HTTP server tests in `src/client_tests.rs` to cover a 429 with `Retry-After: 30` and a non-JSON body, a missing or invalid header, and `retry_delay()` for each case.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: andreban/gemini-rs#21