feat: capture HTTP Retry-After header in Error::retry_delay() (#21) #22

Merged
andreban merged 2 commits from feat/retry-after-header into main 2026-10-28 19:55:32 +00:00
Owner

Closes #21

Changes

  • src/client.rs: error_for_status reads the Retry-After header before it consumes the body, for every non-success response. parse_retry_after accepts only the delay-seconds form (1*DIGIT), so values such as +30 are rejected.
  • src/error.rs: Error::HttpStatus has a new retry_after: Option<Duration> field, and Error::retry_delay() returns it.
  • src/types/error.rs: VertexApiError has a new retry_after field. Serde skips it because it isn't in the JSON body; the client fills it in. VertexApiError::retry_delay() uses google.rpc.RetryInfo when present and falls back to retry_after. This keeps the header on the common shape: a JSON 429 that has no RetryInfo.
  • src/client_tests.rs: the mock server and client setup is now shared through the mock_client and http_response helpers, instead of being copied into every test.

Breaking changes

  • Error::HttpStatus and VertexApiError each have a new public field. Code that destructures them without .., or builds them with a struct literal, needs updating. The crate is already at 0.2.0 and unreleased, so I didn't bump the version again.

Not included

  • HTTP-date form (Retry-After: Wed, 21 Oct 2015 07:28:00 GMT): it returns None. Supporting it would mean adding a date-parsing dependency, and the issue marked it optional.
  • Upper bound on the delay: capping the delay belongs to the caller's retry policy.

Tests

  • Mock server:
    • A non-JSON 429 with Retry-After: 30 gives HttpStatus { retry_after: Some(30s) }.
    • A JSON 429 without RetryInfo gives VertexError with retry_after: Some(30s).
    • A JSON 429 with both RetryInfo (37s) and Retry-After: 30 gives 37s.
    • Errors without the header give None.
  • Header parsing: 30 and 0 parse. An HTTP-date, soon, -1, +30, 1.5 and an empty value give None.
  • retry_delay(): covered for the fallback and for RetryInfo taking precedence, on both VertexApiError and Error.

cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test pass locally.

Closes #21 ## Changes - **`src/client.rs`**: `error_for_status` reads the `Retry-After` header before it consumes the body, for every non-success response. `parse_retry_after` accepts only the delay-seconds form (`1*DIGIT`), so values such as `+30` are rejected. - **`src/error.rs`**: `Error::HttpStatus` has a new `retry_after: Option<Duration>` field, and `Error::retry_delay()` returns it. - **`src/types/error.rs`**: `VertexApiError` has a new `retry_after` field. Serde skips it because it isn't in the JSON body; the client fills it in. `VertexApiError::retry_delay()` uses `google.rpc.RetryInfo` when present and falls back to `retry_after`. This keeps the header on the common shape: a JSON 429 that has no `RetryInfo`. - **`src/client_tests.rs`**: the mock server and client setup is now shared through the `mock_client` and `http_response` helpers, instead of being copied into every test. ## Breaking changes - `Error::HttpStatus` and `VertexApiError` each have a new public field. Code that destructures them without `..`, or builds them with a struct literal, needs updating. The crate is already at 0.2.0 and unreleased, so I didn't bump the version again. ## Not included - **HTTP-date form** (`Retry-After: Wed, 21 Oct 2015 07:28:00 GMT`): it returns `None`. Supporting it would mean adding a date-parsing dependency, and the issue marked it optional. - **Upper bound on the delay**: capping the delay belongs to the caller's retry policy. ## Tests - **Mock server**: - A non-JSON 429 with `Retry-After: 30` gives `HttpStatus { retry_after: Some(30s) }`. - A JSON 429 without `RetryInfo` gives `VertexError` with `retry_after: Some(30s)`. - A JSON 429 with both `RetryInfo` (37s) and `Retry-After: 30` gives 37s. - Errors without the header give `None`. - **Header parsing**: `30` and ` 0 ` parse. An HTTP-date, `soon`, `-1`, `+30`, `1.5` and an empty value give `None`. - **`retry_delay()`**: covered for the fallback and for `RetryInfo` taking precedence, on both `VertexApiError` and `Error`. `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings` and `cargo test` pass locally.
andreban added 1 commit 2026-10-28 08:54:55 +00:00
feat: capture HTTP Retry-After header in Error::retry_delay() (#21)
All checks were successful
Rust / check (pull_request) Successful in 2m41s
2e0016eb25
Error::HttpStatus gains a retry_after field, filled from the response's
Retry-After header (delay-seconds form) before the body is consumed.
Error::retry_delay() now returns it for HttpStatus errors, so a 429 or
503 with a non-Vertex body still exposes the server's retry hint.

Closes #21
andreban added 1 commit 2026-10-28 19:49:47 +00:00
fix: keep Retry-After for JSON error bodies and tighten parsing (#21)
All checks were successful
Rust / check (pull_request) Successful in 3m9s
440b3c7a87
- VertexApiError gains a serde-skipped retry_after field, filled from the
  Retry-After header. VertexApiError::retry_delay() prefers RetryInfo and
  falls back to it, so a JSON 429 without RetryInfo still exposes the
  header delay.
- parse_retry_after rejects anything but ASCII digits; u64::from_str
  alone accepted a leading '+'.
- Client tests share mock_client/http_response helpers instead of
  repeating the mock server setup in every test.
andreban merged commit 21afea80b2 into main 2026-10-28 19:55:32 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: andreban/gemini-rs#22