fix: address code review findings

This commit is contained in:
2026-08-17 22:14:48 +03:00
parent 777fda95a3
commit 78f662c985
5 changed files with 29 additions and 28 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"math/rand"
"net/http"
"net/url"
@@ -189,9 +190,10 @@ func (c *Client) executeRequest(ctx context.Context, url string) (*Response, err
if err != nil {
return nil, fmt.Errorf("request failed: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
io.ReadAll(resp.Body) // Drain body to allow connection reuse
resp.Body.Close()
return nil, newAPIError(resp.StatusCode, resp.Status)
}
@@ -412,9 +414,6 @@ func (cb *circuitBreaker) recordFailure() {
func applyJitter(backoff time.Duration) time.Duration {
jitter := time.Duration(float64(backoff) * 0.1 * (randFloat64()*2 - 1))
if jitter < 0 {
jitter = -jitter
}
return backoff + jitter
}