diff --git a/hcloud/action_test.go b/hcloud/action_test.go index ffaf5ce8..28e32f73 100644 --- a/hcloud/action_test.go +++ b/hcloud/action_test.go @@ -183,11 +183,11 @@ func TestActionClientWatchProgress(t *testing.T) { }, }) case 2: - w.WriteHeader(http.StatusTooManyRequests) + w.WriteHeader(http.StatusConflict) _ = json.NewEncoder(w).Encode(schema.ErrorResponse{ Error: schema.Error{ - Code: string(ErrorCodeRateLimitExceeded), - Message: "ratelimited", + Code: string(ErrorCodeConflict), + Message: "conflict", }, }) return diff --git a/hcloud/client.go b/hcloud/client.go index 3e6a4428..792be9b5 100644 --- a/hcloud/client.go +++ b/hcloud/client.go @@ -270,7 +270,7 @@ func (c *Client) Do(r *http.Request, v interface{}) (*Response, error) { err = errorFromResponse(resp, body) if err == nil { err = fmt.Errorf("hcloud: server responded with status code %d", resp.StatusCode) - } else if isRetryable(err) { + } else if isConflict(err) { c.backoff(retries) retries++ continue @@ -289,12 +289,12 @@ func (c *Client) Do(r *http.Request, v interface{}) (*Response, error) { } } -func isRetryable(error error) bool { +func isConflict(error error) bool { err, ok := error.(Error) if !ok { return false } - return err.Code == ErrorCodeRateLimitExceeded || err.Code == ErrorCodeConflict + return err.Code == ErrorCodeConflict } func (c *Client) backoff(retries int) { diff --git a/hcloud/client_test.go b/hcloud/client_test.go index 7e2b3f22..e6d804bb 100644 --- a/hcloud/client_test.go +++ b/hcloud/client_test.go @@ -183,7 +183,7 @@ func TestClientAll(t *testing.T) { var ( ctx = context.Background() - ratelimited bool + conflicting bool expectedPage = 1 ) @@ -205,13 +205,13 @@ func TestClientAll(t *testing.T) { respBody.Meta.Pagination.Page = 1 respBody.Meta.Pagination.NextPage = 2 case "2": - if !ratelimited { - ratelimited = true - w.WriteHeader(http.StatusTooManyRequests) + if !conflicting { + conflicting = true + w.WriteHeader(http.StatusConflict) json.NewEncoder(w).Encode(schema.ErrorResponse{ Error: schema.Error{ - Code: string(ErrorCodeRateLimitExceeded), - Message: "ratelimited", + Code: string(ErrorCodeConflict), + Message: "conflict", }, }) return @@ -262,11 +262,11 @@ func TestClientDo(t *testing.T) { w.Header().Set("Content-Type", "application/json") switch callCount { case 1: - w.WriteHeader(http.StatusTooManyRequests) + w.WriteHeader(http.StatusConflict) json.NewEncoder(w).Encode(schema.ErrorResponse{ Error: schema.Error{ - Code: string(ErrorCodeRateLimitExceeded), - Message: "ratelimited", + Code: string(ErrorCodeConflict), + Message: "conflict", }, }) case 2: