Skip to content

Commit

Permalink
Merge pull request #5 from electric-saw/retry-policy
Browse files Browse the repository at this point in the history
Adding retry policy for 401 status code.
  • Loading branch information
vfolgosa authored Aug 3, 2022
2 parents 17cae97 + c30e6ca commit 1c1ac7d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ccloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ type specWrap struct {
func (c *ConfluentClient) doRequest(urlPath, method string, body, params interface{}) (*http.Response, error) {
client := retryablehttp.NewClient()
client.RetryMax = 10

client.CheckRetry = func(ctx context.Context, resp *http.Response, err error) (bool, error) {
ok, e := retryablehttp.DefaultRetryPolicy(ctx, resp, err)
if !ok && (resp.StatusCode == http.StatusUnauthorized || resp.StatusCode >= 500 && resp.StatusCode != 501) {
return true, e
}
return ok, nil
}

url, err := url.Parse(c.BaseUrl)
if err != nil {
Expand Down

0 comments on commit 1c1ac7d

Please sign in to comment.