Retry checking refactored using util function.

This commit is contained in:
Musab Gültekin
2021-04-14 09:32:42 +03:00
parent 46c4db6b1a
commit be4d13c0ef
3 changed files with 18 additions and 10 deletions

View File

@ -105,13 +105,11 @@ func (c *Client) DoRequest(req *Request) (resp *Response, err error) {
}
// Retry on http status codes
for _, statusCode := range c.opt.RetryHTTPCodes {
if resp.StatusCode == statusCode {
if req.retryCounter < c.opt.RetryTimes {
req.retryCounter++
internal.Logger.Println("Retrying:", req.URL.String(), resp.StatusCode)
return c.DoRequest(req)
}
if internal.ContainsInt(c.opt.RetryHTTPCodes, resp.StatusCode) {
if req.retryCounter < c.opt.RetryTimes {
req.retryCounter++
internal.Logger.Println("Retrying:", req.URL.String(), resp.StatusCode)
return c.DoRequest(req)
}
}