on main help sign in
refactor: use http.Status... consts

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

commit1be21ca52a7372f2725bd07397bfa5e31f53204c authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateWed 24 Sep 2025, 14:28 (1 year ago) parent5633f24
2 files changed+6−4
internal/llm/provider/anthropic.go+3−2 internal/llm/provider/openai.go+3−2
internal/llm/provider/anthropic.go+3−2
@@ -7,6 +7,7 @@ import (
77 "fmt"
88 "io"
99 "log/slog"
10+ "net/http"
1011 "regexp"
1112 "strconv"
1213 "strings"
@@ -492,12 +493,12 @@ func (a *anthropicClient) shouldRetry(attempts int, err error) (bool, int64, err
492493 return false, 0, fmt.Errorf("maximum retry attempts reached for rate limit: %d retries", maxRetries)
493494 }
494495
495− if apiErr.StatusCode == 401 {
496+ if apiErr.StatusCode == http.StatusUnauthorized {
496497 return false, 0, err
497498 }
498499
499500 // Handle context limit exceeded error (400 Bad Request)
500− if apiErr.StatusCode == 400 {
501+ if apiErr.StatusCode == http.StatusBadRequest {
501502 if adjusted, ok := a.handleContextLimitError(apiErr); ok {
502503 a.adjustedMaxTokens = adjusted
503504 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 (
77 "fmt"
88 "io"
99 "log/slog"
10+ "net/http"
1011 "strings"
1112 "time"
1213
@@ -513,11 +514,11 @@ func (o *openaiClient) shouldRetry(attempts int, err error) (bool, int64, error)
513514 retryAfterValues := []string{}
514515 if errors.As(err, &apiErr) {
515516 // Check for token expiration (401 Unauthorized)
516− if apiErr.StatusCode == 401 {
517+ if apiErr.StatusCode == http.StatusUnauthorized {
517518 return false, 0, err
518519 }
519520
520− if apiErr.StatusCode != 429 && apiErr.StatusCode != 500 {
521+ if apiErr.StatusCode != http.StatusTooManyRequests && apiErr.StatusCode != http.StatusInternalServerError {
521522 return false, 0, err
522523 }
523524