Check response status in all GeminiClient methods and add Error::is_retryable()
#10
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
#4 added non-2xx status handling to
GeminiClient::stream_generate_content: it parsesGenerateContentResponseErrorintoError::VertexErrorand falls back toError::HttpStatus { status, body }for non-JSON error bodies.generate_content,count_tokens,text_embeddingsandpredict_imageinsrc/client.rsstill skip the status check and passresp.text().await?straight intoserde_json::from_str.Impact
502/503/504on:generateContent,generate_contentreturnsError::Serde(...)instead ofError::HttpStatus { status, body }.VertexModelindevrel-pr-reviewer) maintain their ownis_retryable_vertex_error(&gemini_rs::error::Error)classifier and tests — and a non-JSON503fromgenerate_contentis misclassified there as a non-retryableError::Serde.Proposed fix
Extract a shared
Self::error_for_status(response).await?helper onGeminiClient(matchinggeologia::GeminiClient::error_for_status) and call it fromgenerate_content,stream_generate_content,count_tokens,text_embeddingsandpredict_image.Add
pub fn is_retryable(&self) -> boolongemini_rs::error::Error, following the Vertex AI API errors guidance. Returntruefor:VertexErrorwith code429/500/503, or statusRESOURCE_EXHAUSTED/INTERNAL/UNKNOWN/UNAVAILABLE(a 500 can carry eitherINTERNALorUNKNOWN)HttpStatuswith429/500/502/503(502 covers non-JSON gateway errors from proxies)HttpClienterrorsDon't treat
504 DEADLINE_EXCEEDEDas retryable: the docs say it means the client deadline is shorter than the server default, and recommend removing or lengthening the deadline rather than retrying.This lets downstream callers drop their own Vertex error classification.
Notes for callers
The docs recommend retrying at most twice, with a minimum delay of 1 second and exponential backoff after that.
is_retryable()should only classify errors; retry/backoff policy stays with the caller.