Skip to content

Commit

Permalink
fix(retry): reset body on each request (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleSanderson authored Apr 18, 2024
1 parent 44528cc commit e5d8912
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ func (c *Client) retryDo(ctx context.Context, req *http.Request) (*http.Response

if req != nil && req.Body != nil {
originalBody, err = copyBody(req.Body)
resetBody(req, originalBody)
}

if err != nil {
Expand All @@ -257,6 +256,10 @@ func (c *Client) retryDo(ctx context.Context, req *http.Request) (*http.Response

// try request and if fail run 10 retries
err = retry.Do(func() error {
if req != nil && req.Body != nil {
resetBody(req, originalBody)
}

resp, err = c.http.Do(req)

if err == nil {
Expand All @@ -265,10 +268,6 @@ func (c *Client) retryDo(ctx context.Context, req *http.Request) (*http.Response
return errors.Wrap(err, "qbit re-login failed")
}

if req.Body != nil {
resetBody(req, originalBody)
}

retry.Delay(100 * time.Millisecond)

return errors.New("qbit re-login")
Expand Down

0 comments on commit e5d8912

Please sign in to comment.