diff options
Diffstat (limited to 'internal/retry')
| -rw-r--r-- | internal/retry/backoff.go | 11 | ||||
| -rw-r--r-- | internal/retry/backoff_test.go | 7 |
2 files changed, 16 insertions, 2 deletions
diff --git a/internal/retry/backoff.go b/internal/retry/backoff.go index a372b37..72b923c 100644 --- a/internal/retry/backoff.go +++ b/internal/retry/backoff.go @@ -22,7 +22,13 @@ const maxBackoffDelay = 5 * time.Minute // OpenAI-compatible error text (internal/llm); "rate_limit_error", // "overloaded_error", and "529" additionally match Anthropic's Messages API // error shape (HTTP 429 with error.type "rate_limit_error", or HTTP 529 -// with error.type "overloaded_error" — see internal/provider/anthropic). +// with error.type "overloaded_error" — see internal/provider/anthropic); +// "resource_exhausted" additionally matches Gemini's generateContent API +// error shape (HTTP 429 with error.status "RESOURCE_EXHAUSTED" — see +// internal/provider/google). The plain "429" check above already covers +// Gemini's HTTP status code, but the status string is matched too for +// parity with how the Anthropic error types are matched by name, not just +// by status code. func IsRateLimitError(err error) bool { if err == nil { return false @@ -34,7 +40,8 @@ func IsRateLimitError(err error) bool { strings.Contains(msg, "overloaded") || strings.Contains(msg, "rate_limit_error") || strings.Contains(msg, "overloaded_error") || - strings.Contains(msg, "529") + strings.Contains(msg, "529") || + strings.Contains(msg, "resource_exhausted") } // ParseRetryAfter extracts a Retry-After duration from an error message. diff --git a/internal/retry/backoff_test.go b/internal/retry/backoff_test.go index d605f29..4d893c3 100644 --- a/internal/retry/backoff_test.go +++ b/internal/retry/backoff_test.go @@ -59,6 +59,13 @@ func TestIsRateLimitError_HTTP529(t *testing.T) { } } +func TestIsRateLimitError_GoogleResourceExhausted(t *testing.T) { + err := errors.New(`google: http 429 RESOURCE_EXHAUSTED: You exceeded your current quota.`) + if !IsRateLimitError(err) { + t.Error("want true for Gemini 'RESOURCE_EXHAUSTED' shape, got false") + } +} + func TestIsRateLimitError_NonRateLimitError(t *testing.T) { err := errors.New("claude exited with error: exit status 1") if IsRateLimitError(err) { |
