feat: expose Gemini RetryInfo retry_delay() on VertexApiError and Error (#19) #20
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "gemini-rs"
|
name = "gemini-rs"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|||||||
23
src/error.rs
23
src/error.rs
@@ -116,16 +116,18 @@ impl Error {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
fn vertex_error(code: i32, status: &str, details: Option<Vec<serde_json::Value>>) -> Error {
|
||||||
fn vertex_error_retryable_classification() {
|
|
||||||
let make_err = |code: i32, status: &str| {
|
|
||||||
Error::VertexError(types::VertexApiError {
|
Error::VertexError(types::VertexApiError {
|
||||||
code,
|
code,
|
||||||
message: "test".to_string(),
|
message: "test".to_string(),
|
||||||
status: status.to_string(),
|
status: status.to_string(),
|
||||||
details: None,
|
details,
|
||||||
})
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn vertex_error_retryable_classification() {
|
||||||
|
let make_err = |code: i32, status: &str| vertex_error(code, status, None);
|
||||||
|
|
||||||
// Retryable codes
|
// Retryable codes
|
||||||
assert!(make_err(429, "TOO_MANY_REQUESTS").is_retryable());
|
assert!(make_err(429, "TOO_MANY_REQUESTS").is_retryable());
|
||||||
@@ -167,15 +169,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn retry_delay_delegates_to_vertex_error() {
|
fn retry_delay_delegates_to_vertex_error() {
|
||||||
let err = Error::VertexError(types::VertexApiError {
|
let err = vertex_error(
|
||||||
code: 429,
|
429,
|
||||||
message: "Quota exceeded".to_string(),
|
"RESOURCE_EXHAUSTED",
|
||||||
status: "RESOURCE_EXHAUSTED".to_string(),
|
Some(vec![serde_json::json!({
|
||||||
details: Some(vec![serde_json::json!({
|
|
||||||
"@type": "type.googleapis.com/google.rpc.RetryInfo",
|
"@type": "type.googleapis.com/google.rpc.RetryInfo",
|
||||||
"retryDelay": "15s"
|
"retryDelay": "15s"
|
||||||
})]),
|
})]),
|
||||||
});
|
);
|
||||||
assert_eq!(err.retry_delay(), Some(Duration::from_secs(15)));
|
assert_eq!(err.retry_delay(), Some(Duration::from_secs(15)));
|
||||||
|
|
||||||
assert_eq!(Error::NoCandidatesError.retry_delay(), None);
|
assert_eq!(Error::NoCandidatesError.retry_delay(), None);
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ fn parse_duration(s: &str) -> Option<Duration> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let parsed: u32 = frac.parse().ok()?;
|
let parsed: u32 = frac.parse().ok()?;
|
||||||
parsed.checked_mul(10u32.pow(9 - frac.len() as u32))?
|
parsed * 10u32.pow(9 - frac.len() as u32)
|
||||||
}
|
}
|
||||||
None => 0,
|
None => 0,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user