From afbd035824df54aa414ed66955aa2bd0301192ea Mon Sep 17 00:00:00 2001 From: AlexanderMann Date: Fri, 4 Mar 2022 10:47:53 -0600 Subject: [PATCH] Feature: Retry errors from CCI 3 times in order to sidestep retryable errors --- circleci/client/rest/client.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/circleci/client/rest/client.go b/circleci/client/rest/client.go index 8b3db2d4..587a06d6 100644 --- a/circleci/client/rest/client.go +++ b/circleci/client/rest/client.go @@ -60,10 +60,25 @@ func (c *Client) NewRequest(method string, u *url.URL, payload interface{}) (req } func (c *Client) DoRequest(req *http.Request, resp interface{}) (statusCode int, err error) { - httpResp, err := c.client.Do(req) + var ( + err error + httpResp *http.Response + retries int = 3 + ) + for retries > 0 { + httpResp, err = c.client.Do(req) + + if err != nil { + retries -= 1 + } else { + break + } + } + if err != nil { return 0, err } + defer httpResp.Body.Close() if httpResp.StatusCode >= 300 {