fix attempts
This commit is contained in:
@ -147,20 +147,22 @@ func (c *Client) doWithRetry(req *http.Request, expectedCode int) (*http.Respons
|
||||
attempt := 0
|
||||
maxAttempts := 5
|
||||
for {
|
||||
attempt++
|
||||
resp, err := c.httpCli().Do(req)
|
||||
if err != nil {
|
||||
if attempt < maxAttempts-1 {
|
||||
if attempt < maxAttempts {
|
||||
continue
|
||||
} else {
|
||||
return resp, err
|
||||
return resp, fmt.Errorf("after %d attempts: %w", attempt, err)
|
||||
}
|
||||
}
|
||||
if resp.StatusCode != expectedCode {
|
||||
if attempt < maxAttempts-1 {
|
||||
resp.Body.Close()
|
||||
defer resp.Body.Close()
|
||||
dump, _ := httputil.DumpResponse(resp, true)
|
||||
if attempt < maxAttempts {
|
||||
continue
|
||||
} else {
|
||||
return resp, err
|
||||
return resp, fmt.Errorf("after %d attempts, status: %d, body: %s", attempt, resp.StatusCode, string(dump))
|
||||
}
|
||||
|
||||
}
|
||||
|
BIN
profile001.pdf
Normal file
BIN
profile001.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user