feat: check response status in all GeminiClient methods and add Error::is_retryable() (#10) #15

Merged
andreban merged 1 commits from feat/error-status-and-retryable into main 2026-10-26 19:26:47 +00:00
Owner

Fixes #10

Summary

  • Extracts Self::error_for_status(response).await? on GeminiClient to check response status across all client methods:
    • Parses GenerateContentResponseError into Error::VertexError on non-success status.
    • Falls back to Error::HttpStatus { status, body } for non-JSON error bodies (e.g., 502/503 from proxies or gateways).
  • Invokes error_for_status in generate_content, stream_generate_content, count_tokens, text_embeddings, and predict_image.
  • Adds pub fn is_retryable(&self) -> bool on gemini_rs::error::Error according to Vertex AI error guidance:
    • VertexError: returns true for HTTP status codes 429, 500, 503 or gRPC status RESOURCE_EXHAUSTED, INTERNAL, UNKNOWN, UNAVAILABLE.
    • HttpStatus: returns true for status codes 429, 500, 502, 503 (excluding 504 DEADLINE_EXCEEDED).
    • HttpClient: returns true for reqwest::Error timeouts and connection failures (is_timeout() / is_connect()).
    • All other errors return false.

Testing

  • Added unit tests in src/error.rs testing retryable and non-retryable classifications for VertexError, HttpStatus, and other error variants.
  • Added tests in src/client_tests.rs verifying that generate_content, count_tokens, text_embeddings, and predict_image return Error::HttpStatus on non-JSON error responses, and generate_content returns Error::VertexError on 400 JSON.
  • cargo test (28 passed) and cargo clippy pass cleanly.
Fixes #10 ## Summary - Extracts `Self::error_for_status(response).await?` on `GeminiClient` to check response status across all client methods: - Parses `GenerateContentResponseError` into `Error::VertexError` on non-success status. - Falls back to `Error::HttpStatus { status, body }` for non-JSON error bodies (e.g., 502/503 from proxies or gateways). - Invokes `error_for_status` in `generate_content`, `stream_generate_content`, `count_tokens`, `text_embeddings`, and `predict_image`. - Adds `pub fn is_retryable(&self) -> bool` on `gemini_rs::error::Error` according to Vertex AI error guidance: - `VertexError`: returns true for HTTP status codes 429, 500, 503 or gRPC status `RESOURCE_EXHAUSTED`, `INTERNAL`, `UNKNOWN`, `UNAVAILABLE`. - `HttpStatus`: returns true for status codes 429, 500, 502, 503 (excluding 504 `DEADLINE_EXCEEDED`). - `HttpClient`: returns true for `reqwest::Error` timeouts and connection failures (`is_timeout()` / `is_connect()`). - All other errors return false. ## Testing - Added unit tests in `src/error.rs` testing retryable and non-retryable classifications for `VertexError`, `HttpStatus`, and other error variants. - Added tests in `src/client_tests.rs` verifying that `generate_content`, `count_tokens`, `text_embeddings`, and `predict_image` return `Error::HttpStatus` on non-JSON error responses, and `generate_content` returns `Error::VertexError` on 400 JSON. - `cargo test` (28 passed) and `cargo clippy` pass cleanly.
andreban added 1 commit 2026-10-26 19:25:57 +00:00
andreban merged commit 7d5c6e3e28 into main 2026-10-26 19:26:47 +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#15