From a42f99ecf3e625ae44652cb3f1fa989262a124c5 Mon Sep 17 00:00:00 2001 From: Vinicius Date: Wed, 3 Aug 2022 16:14:48 -0300 Subject: [PATCH] Update cluster_client.go adding 401 status code retry --- ccloud/cluster/cluster_client.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ccloud/cluster/cluster_client.go b/ccloud/cluster/cluster_client.go index 1052832..c5050c5 100644 --- a/ccloud/cluster/cluster_client.go +++ b/ccloud/cluster/cluster_client.go @@ -1,6 +1,7 @@ package cluster import ( + "context" "encoding/json" "fmt" "net/http" @@ -41,6 +42,14 @@ func (c *ConfluentClusterClient) doRequest(base string, urlPath, method string, 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 + } + if base == "" { base = c.BaseUrl }