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))
| 1203 | // withRetry takes a generic function that sends an http request and retries |
| 1204 | // only when the returned response has a >=500 status code. |
| 1205 | func (a *API) withRetry(f func() (*http.Response, error)) (*http.Response, error) { |
| 1206 | bo := backoff.NewConstantBackOff(a.retryBackoff) |
| 1207 | return backoff.RetryWithData(func() (*http.Response, error) { |
| 1208 | resp, err := f() |
| 1209 | if err != nil { |
| 1210 | return nil, backoff.Permanent(err) |
| 1211 | } |
| 1212 | if resp.StatusCode < 500 { |
| 1213 | return resp, nil |
| 1214 | } |
| 1215 | return nil, fmt.Errorf("received response with status code %d", resp.StatusCode) |
| 1216 | }, backoff.WithMaxRetries(bo, 3)) |
| 1217 | } |
| 1218 | |
| 1219 | // ExternalHTTPClient returns an HTTP client for requests to non-GitHub hosts. |
| 1220 | // It must not carry GitHub authentication credentials. |
no test coverage detected