Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make old ratelimit error code work as expected #74

Merged
merged 2 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changes

## master

* Make clients using the old error code for ratelimiting work as expected
([issue #73](https://github.com/hetznercloud/hcloud-go/issues/73))

## v1.3.0

* Support passing user data on server creation ([issue #70](https://github.com/hetznercloud/hcloud-go/issues/70))
Expand Down
2 changes: 1 addition & 1 deletion hcloud/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (c *ActionClient) WatchProgress(ctx context.Context, action *Action) (<-cha

action, _, err := c.GetByID(ctx, action.ID)
if err != nil {
if err, ok := err.(Error); ok && err.Code == ErrorCodeLimitReached {
if err, ok := err.(Error); ok && err.Code == ErrorCodeRateLimitExceeded {
c.client.backoff(retries)
retries++
continue
Expand Down
2 changes: 1 addition & 1 deletion hcloud/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestActionClientWatchProgress(t *testing.T) {
w.WriteHeader(http.StatusTooManyRequests)
json.NewEncoder(w).Encode(schema.ErrorResponse{
Error: schema.Error{
Code: "limit_reached",
Code: ErrorCodeRateLimitExceeded,
Message: "ratelimited",
},
})
Expand Down
8 changes: 7 additions & 1 deletion hcloud/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ const (
ErrorCodeInvalidInput = "invalid_input" // Validation error

// Deprecated error codes
ErrorCodeLimitReached = "limit_reached"

// The actual value of this error code is limit_reached. The new error code
// rate_limit_exceeded for ratelimiting was introduced before Hetzner Cloud
// launched into the public. To make clients using the old error code still
// work as expected, we set the value of the old error code to that of the
// new error code.
ErrorCodeLimitReached = ErrorCodeRateLimitExceeded
)

// Error is an error returned from the API.
Expand Down