Skip to content

Commit 3def8ef

Browse files
authored
feat: retry request on API timeout error (#797)
This error code explicitly document that the request should be retried.
1 parent 3c5f4b1 commit 3def8ef

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

hcloud/client_handler_retry.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ func retryPolicy(resp *Response, err error) bool {
6666
return true
6767
case ErrorCodeRateLimitExceeded:
6868
return true
69+
case ErrorCodeTimeout:
70+
return true
6971
}
7072
case errors.Is(err, ErrStatusCode):
7173
switch resp.Response.StatusCode {

hcloud/client_handler_retry_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ func TestRetryPolicy(t *testing.T) {
130130
resp: fakeResponse(t, 503, ``, false),
131131
want: false,
132132
},
133+
{
134+
name: "server returns timeout error",
135+
resp: fakeResponse(t, 504, `{"error":{"code":"timeout"}}`, true),
136+
want: true,
137+
},
133138
{
134139
name: "api returns rate_limit_exceeded error",
135140
resp: fakeResponse(t, 429, `{"error":{"code":"rate_limit_exceeded"}}`, true),

hcloud/hcloud.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ When the API returned an HTTP error, with the status code:
2424
When the API returned an application error, with the code:
2525
- [ErrorCodeConflict]
2626
- [ErrorCodeRateLimitExceeded]
27+
- [ErrorCodeTimeout]
2728
2829
Changes to the retry policy might occur between releases, and will not be considered
2930
breaking changes.

0 commit comments

Comments
 (0)