feat: expose Gemini RetryInfo retry_delay() on VertexApiError and Error (#19)
All checks were successful
Rust / check (pull_request) Successful in 2m40s

VertexApiError.details is now Option<Vec<serde_json::Value>> so that
unknown google.rpc.* detail types (e.g. RetryInfo, QuotaFailure) no
longer break deserialization and fall back to Error::HttpStatus. The
unused ErrorType, ErrorInfoMetadata, FieldViolation and Link types are
removed.

Add VertexApiError::retry_delay() which parses the protobuf duration in a
google.rpc.RetryInfo entry, and Error::retry_delay() which delegates to it.

Closes #19
This commit is contained in:
2026-10-28 08:35:53 +00:00
parent 4791125943
commit cecc14d31e
2 changed files with 265 additions and 27 deletions

View File

@@ -1,4 +1,5 @@
use std::fmt::Display;
use std::time::Duration;
use tokio_util::codec::LinesCodecError;
@@ -100,6 +101,15 @@ impl Error {
_ => false,
}
}
/// Returns the server-recommended retry delay if this error is a
/// [`Error::VertexError`] containing a `google.rpc.RetryInfo` detail entry.
pub fn retry_delay(&self) -> Option<Duration> {
match self {
Error::VertexError(e) => e.retry_delay(),
_ => None,
}
}
}
#[cfg(test)]
@@ -155,6 +165,27 @@ mod tests {
assert!(!make_err(reqwest::StatusCode::GATEWAY_TIMEOUT).is_retryable());
}
#[test]
fn retry_delay_delegates_to_vertex_error() {
let err = Error::VertexError(types::VertexApiError {
code: 429,
message: "Quota exceeded".to_string(),
status: "RESOURCE_EXHAUSTED".to_string(),
details: Some(vec![serde_json::json!({
"@type": "type.googleapis.com/google.rpc.RetryInfo",
"retryDelay": "15s"
})]),
});
assert_eq!(err.retry_delay(), Some(Duration::from_secs(15)));
assert_eq!(Error::NoCandidatesError.retry_delay(), None);
let http_err = Error::HttpStatus {
status: reqwest::StatusCode::TOO_MANY_REQUESTS,
body: "error".to_string(),
};
assert_eq!(http_err.retry_delay(), None);
}
#[test]
fn other_errors_not_retryable() {
assert!(!Error::NoCandidatesError.is_retryable());