Skip to content

Commit

Permalink
add using retryablehttp with custom CheckRetry
Browse files Browse the repository at this point in the history
  • Loading branch information
l-with authored and timohirt committed Feb 18, 2022
1 parent 5ae261d commit 3c9338b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hetznerdns/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -47,7 +48,13 @@ func NewClient(apiToken string) (*Client, error) {

func (c *Client) doHTTPRequest(apiToken string, method string, url string, body io.Reader) (*http.Response, error) {
retryableClient := retryablehttp.NewClient()
retryableClient.Backoff = retryablehttp.DefaultBackoff
retryableClient.CheckRetry = func(ctx context.Context, resp *http.Response, err error) (bool, error) {
ok, err := retryablehttp.DefaultRetryPolicy(ctx, resp, err)
if !ok && resp.StatusCode == http.StatusUnprocessableEntity {
return true, nil
}
return ok, err
}
retryableClient.RetryMax = 10
client := retryableClient.StandardClient()

Expand Down

0 comments on commit 3c9338b

Please sign in to comment.