Skip to content

Commit

Permalink
Make old ratelimit error code work as expected (#74)
Browse files Browse the repository at this point in the history
* Make old ratelimit error code work as expected

Fixes #73.

* Use new RateLimitExceededCode in ActionClient
  • Loading branch information
thcyron authored and thetechnick committed Feb 13, 2018
1 parent c45fbb2 commit f1f5a62
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
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

0 comments on commit f1f5a62

Please sign in to comment.