From 1be21ca52a7372f2725bd07397bfa5e31f53204c Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 24 Sep 2025 14:28:01 -0300 Subject: [PATCH] refactor: use http.Status... consts Signed-off-by: Carlos Alexandro Becker --- internal/llm/provider/anthropic.go | 5 +++-- internal/llm/provider/openai.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/llm/provider/anthropic.go b/internal/llm/provider/anthropic.go index d07b657e4ca2861bdbf8f82401a9283c82263e57..cfe8f6210fce8ad75eb930374a618e32ac1e2a03 100644 --- a/internal/llm/provider/anthropic.go +++ b/internal/llm/provider/anthropic.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "log/slog" + "net/http" "regexp" "strconv" "strings" @@ -492,12 +493,12 @@ func (a *anthropicClient) shouldRetry(attempts int, err error) (bool, int64, err return false, 0, fmt.Errorf("maximum retry attempts reached for rate limit: %d retries", maxRetries) } - if apiErr.StatusCode == 401 { + if apiErr.StatusCode == http.StatusUnauthorized { return false, 0, err } // Handle context limit exceeded error (400 Bad Request) - if apiErr.StatusCode == 400 { + if apiErr.StatusCode == http.StatusBadRequest { if adjusted, ok := a.handleContextLimitError(apiErr); ok { a.adjustedMaxTokens = adjusted slog.Debug("Adjusted max_tokens due to context limit", "new_max_tokens", adjusted) diff --git a/internal/llm/provider/openai.go b/internal/llm/provider/openai.go index 587f01384a151a940dcbcdcecb71eb5ba27a554b..d2563cfec5104145e8571d40540e9d7acd886a1d 100644 --- a/internal/llm/provider/openai.go +++ b/internal/llm/provider/openai.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "log/slog" + "net/http" "strings" "time" @@ -513,11 +514,11 @@ func (o *openaiClient) shouldRetry(attempts int, err error) (bool, int64, error) retryAfterValues := []string{} if errors.As(err, &apiErr) { // Check for token expiration (401 Unauthorized) - if apiErr.StatusCode == 401 { + if apiErr.StatusCode == http.StatusUnauthorized { return false, 0, err } - if apiErr.StatusCode != 429 && apiErr.StatusCode != 500 { + if apiErr.StatusCode != http.StatusTooManyRequests && apiErr.StatusCode != http.StatusInternalServerError { return false, 0, err }