MCPcopy Index your code
hub / github.com/cli/cli / withRetry

Method withRetry

internal/codespaces/api/api.go:1205–1217  ·  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

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

Callers 2

GetCodespaceMethod · 0.95
StartCodespaceMethod · 0.95

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected