diff --git a/clientutil/retry.go b/clientutil/retry.go index ae5159f1cc0b053d4ae54d6c7c8d2b68834b7bda..054d301607ea3575da8896e9110e39ada5fba3a2 100644 --- a/clientutil/retry.go +++ b/clientutil/retry.go @@ -33,12 +33,20 @@ func Retry(op backoff.Operation, b backoff.BackOff) error { return backoff.Retry(innerOp, b) } -var errHTTPBackOff = errors.New("http status 503") +var errHTTPBackOff = errors.New("temporary http error") + +func isStatusTemporary(code int) bool { + switch code { + case http.StatusTooManyRequests, http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout: + return true + default: + return false + } +} // RetryHTTPDo retries an HTTP request until it succeeds, according to // the backoff policy b. It will retry on temporary network errors and -// upon receiving specific throttling HTTP errors (currently just -// status code 503). +// upon receiving specific temporary HTTP errors. func RetryHTTPDo(client *http.Client, req *http.Request, b backoff.BackOff) (*http.Response, error) { var resp *http.Response op := func() error { @@ -49,7 +57,7 @@ func RetryHTTPDo(client *http.Client, req *http.Request, b backoff.BackOff) (*ht var err error resp, err = client.Do(req) - if err == nil && resp.StatusCode == 503 { + if err == nil && isStatusTemporary(resp.StatusCode) { resp.Body.Close() return errHTTPBackOff }