on main help sign in
refactor: use http.Status... consts
1be21caCarlos Alexandro Becker
internal/llm/provider/anthropic.go+3−2
@@ -7,6 +7,7 @@ import (
7 "fmt"
7 "fmt"
8 "io"
8 "io"
9 "log/slog"
9 "log/slog"
10+ "net/http"
10 "regexp"
11 "regexp"
11 "strconv"
12 "strconv"
12 "strings"
13 "strings"
@@ -492,12 +493,12 @@ func (a *anthropicClient) shouldRetry(attempts int, err error) (bool, int64, err
492 return false, 0, fmt.Errorf("maximum retry attempts reached for rate limit: %d retries", maxRetries)
493 return false, 0, fmt.Errorf("maximum retry attempts reached for rate limit: %d retries", maxRetries)
493 }
494 }
494
495
495− if apiErr.StatusCode == 401 {
496+ if apiErr.StatusCode == http.StatusUnauthorized {
496 return false, 0, err
497 return false, 0, err
497 }
498 }
498
499
499 // Handle context limit exceeded error (400 Bad Request)
500 // Handle context limit exceeded error (400 Bad Request)
500− if apiErr.StatusCode == 400 {
501+ if apiErr.StatusCode == http.StatusBadRequest {
501 if adjusted, ok := a.handleContextLimitError(apiErr); ok {
502 if adjusted, ok := a.handleContextLimitError(apiErr); ok {
502 a.adjustedMaxTokens = adjusted
503 a.adjustedMaxTokens = adjusted
503 slog.Debug("Adjusted max_tokens due to context limit", "new_max_tokens", adjusted)
504 slog.Debug("Adjusted max_tokens due to context limit", "new_max_tokens", adjusted)
internal/llm/provider/openai.go+3−2
@@ -7,6 +7,7 @@ import (
7 "fmt"
7 "fmt"
8 "io"
8 "io"
9 "log/slog"
9 "log/slog"
10+ "net/http"
10 "strings"
11 "strings"
11 "time"
12 "time"
12
13
@@ -513,11 +514,11 @@ func (o *openaiClient) shouldRetry(attempts int, err error) (bool, int64, error)
513 retryAfterValues := []string{}
514 retryAfterValues := []string{}
514 if errors.As(err, &apiErr) {
515 if errors.As(err, &apiErr) {
515 // Check for token expiration (401 Unauthorized)
516 // Check for token expiration (401 Unauthorized)
516− if apiErr.StatusCode == 401 {
517+ if apiErr.StatusCode == http.StatusUnauthorized {
517 return false, 0, err
518 return false, 0, err
518 }
519 }
519
520
520− if apiErr.StatusCode != 429 && apiErr.StatusCode != 500 {
521+ if apiErr.StatusCode != http.StatusTooManyRequests && apiErr.StatusCode != http.StatusInternalServerError {
521 return false, 0, err
522 return false, 0, err
522 }
523 }
523
524