withRetry takes a generic function that sends an http request and retries only when the returned response has a >=500 status code.
(f func() (*http.Response, error))
| 1297 | // withRetry takes a generic function that sends an http request and retries |
| 1298 | // only when the returned response has a >=500 status code. |
| 1299 | func (a *API) withRetry(f func() (*http.Response, error)) (*http.Response, error) { |
| 1300 | bo := backoff.NewConstantBackOff(a.retryBackoff) |
| 1301 | return backoff.RetryWithData(func() (*http.Response, error) { |
| 1302 | resp, err := f() |
| 1303 | if err != nil { |
| 1304 | return nil, backoff.Permanent(err) |
| 1305 | } |
| 1306 | if resp.StatusCode < 500 { |
| 1307 | return resp, nil |
| 1308 | } |
| 1309 | return nil, fmt.Errorf("received response with status code %d", resp.StatusCode) |
| 1310 | }, backoff.WithMaxRetries(bo, 3)) |
| 1311 | } |
| 1312 | |
| 1313 | // ExternalHTTPClient returns an HTTP client for requests to non-GitHub hosts. |
| 1314 | // It must not carry GitHub authentication credentials. |
no test coverage detected