Skip to content

Commit

Permalink
Move logging-related code under the if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ash2k committed Oct 15, 2021
1 parent 2467a3e commit dbd0367
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,6 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
for i := 0; ; i++ {
attempt++

var code int // HTTP response code

// Always rewind the request body when non-nil.
if req.body != nil {
body, err := req.body()
Expand Down Expand Up @@ -599,9 +597,6 @@ func (c *Client) Do(req *Request) (*http.Response, error) {

// Attempt the request
resp, doErr = c.HTTPClient.Do(req.Request)
if resp != nil {
code = resp.StatusCode
}

// Check if we should continue with retries.
shouldRetry, checkErr = c.CheckRetry(req.Context(), resp, doErr)
Expand Down Expand Up @@ -646,11 +641,11 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
}

wait := c.Backoff(c.RetryWaitMin, c.RetryWaitMax, i, resp)
desc := fmt.Sprintf("%s %s", req.Method, req.URL)
if code > 0 {
desc = fmt.Sprintf("%s (status: %d)", desc, code)
}
if logger != nil {
desc := fmt.Sprintf("%s %s", req.Method, req.URL)
if resp != nil {
desc = fmt.Sprintf("%s (status: %d)", desc, resp.StatusCode)
}
switch v := logger.(type) {
case LeveledLogger:
v.Debug("retrying request", "request", desc, "timeout", wait, "remaining", remain)
Expand Down

0 comments on commit dbd0367

Please sign in to comment.