fix: address code review findings
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user