diff --git a/hcloud/client_handler_retry.go b/hcloud/client_handler_retry.go index 10aa086a..eb5c22c3 100644 --- a/hcloud/client_handler_retry.go +++ b/hcloud/client_handler_retry.go @@ -66,6 +66,8 @@ func retryPolicy(resp *Response, err error) bool { return true case ErrorCodeRateLimitExceeded: return true + case ErrorCodeBadGateway: + return true case ErrorCodeTimeout: return true } diff --git a/hcloud/client_handler_retry_test.go b/hcloud/client_handler_retry_test.go index 44e5710a..fc71273b 100644 --- a/hcloud/client_handler_retry_test.go +++ b/hcloud/client_handler_retry_test.go @@ -120,6 +120,11 @@ func TestRetryPolicy(t *testing.T) { resp: fakeResponse(t, 502, ``, false), want: true, }, + { + name: "api returns bad_gateway error", + resp: fakeResponse(t, 502, `{"error":{"code":"bad_gateway"}}`, true), + want: true, + }, { name: "api returns unavailable error", resp: fakeResponse(t, 503, `{"error":{"code":"unavailable"}}`, true), diff --git a/hcloud/error.go b/hcloud/error.go index 2b96a10f..98cfbaf1 100644 --- a/hcloud/error.go +++ b/hcloud/error.go @@ -33,6 +33,7 @@ const ( ErrorCodeResourceLocked ErrorCode = "resource_locked" // The resource is locked. The caller should contact support ErrorCodeServerError ErrorCode = "server_error" // Error within the API backend ErrorCodeTokenReadonly ErrorCode = "token_readonly" // The token is only allowed to perform GET requests + ErrorCodeBadGateway ErrorCode = "bad_gateway" // The request could not be answered by the API backend, please retry ErrorCodeTimeout ErrorCode = "timeout" // The request could not be answered in time, please retry ErrorUnsupportedError ErrorCode = "unsupported_error" // The given resource does not support this ErrorDeprecatedAPIEndpoint ErrorCode = "deprecated_api_endpoint" // The request can not be answered because the API functionality was removed diff --git a/hcloud/hcloud.go b/hcloud/hcloud.go index 28188e5f..92a29887 100644 --- a/hcloud/hcloud.go +++ b/hcloud/hcloud.go @@ -72,6 +72,7 @@ When the API returned an HTTP error, with the status code: When the API returned an application error, with the code: - [ErrorCodeConflict] - [ErrorCodeRateLimitExceeded] + - [ErrorCodeBadGateway] - [ErrorCodeTimeout] Changes to the retry policy might occur between releases, and will not be considered