fix: keep Retry-After for JSON error bodies and tighten parsing (#21)
All checks were successful
Rust / check (pull_request) Successful in 3m9s

- 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.
This commit is contained in:
2026-10-28 19:49:45 +00:00
parent 2e0016eb25
commit 440b3c7a87
4 changed files with 195 additions and 217 deletions

View File

@@ -107,7 +107,8 @@ impl Error {
/// Returns the server-recommended retry delay, if any.
///
/// - `VertexError`: the delay from a `google.rpc.RetryInfo` detail entry.
/// - `VertexError`: the delay from a `google.rpc.RetryInfo` detail entry, falling
/// back to the response's `Retry-After` header.
/// - `HttpStatus`: the delay from the response's `Retry-After` header.
pub fn retry_delay(&self) -> Option<Duration> {
match self {
@@ -128,6 +129,7 @@ mod tests {
message: "test".to_string(),
status: status.to_string(),
details,
retry_after: None,
})
}