MCPcopy Create free account
hub / github.com/cli/cli / withRetry

Method withRetry

internal/codespaces/api/api.go:1299–1311  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

1297// withRetry takes a generic function that sends an http request and retries
1298// only when the returned response has a >=500 status code.
1299func (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.

Callers 2

GetCodespaceMethod · 0.95
StartCodespaceMethod · 0.95

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected