@@ -59,21 +59,15 @@ import (
5959// - The decision to retry requests is based on the idempotency of the HTTP method and the client's retry configuration,
6060// including maximum retry attempts and total retry duration.
6161func (c * Client ) DoRequest (method , endpoint string , body , out interface {}) (* http.Response , error ) {
62- if ! c .config .RetryEligiableRequests {
63- return c .requestNoRetries (method , endpoint , body , out )
64- }
6562
66- if IsIdempotentHTTPMethod (method ) {
67- return c .requestWithRetries (method , endpoint , body , out )
68- } else if ! IsIdempotentHTTPMethod (method ) {
63+ if ! c .config .RetryEligiableRequests || ! isIdempotentHTTPMethod (method ) {
6964 return c .requestNoRetries (method , endpoint , body , out )
7065 }
7166
72- return nil , fmt . Errorf ( "unsupported http method: %s" , method )
67+ return c . requestWithRetries ( method , endpoint , body , out )
7368}
7469
75- // region comment
76- // executeRequestWithRetries executes an HTTP request using the specified method, endpoint, request body, and output variable.
70+ // requestWithRetries executes an HTTP request using the specified method, endpoint, request body, and output variable.
7771// It is designed for idempotent HTTP methods (GET, PUT, DELETE), where the request can be safely retried in case of
7872// transient errors or rate limiting. The function implements a retry mechanism that respects the client's configuration
7973// for maximum retry attempts and total retry duration. Each retry attempt uses exponential backoff with jitter to avoid
@@ -102,7 +96,6 @@ func (c *Client) DoRequest(method, endpoint string, body, out interface{}) (*htt
10296// - The function respects the client's concurrency token, acquiring and releasing it as needed to ensure safe concurrent
10397// operations.
10498// - The retry mechanism employs exponential backoff with jitter to mitigate the impact of retries on the server.
105- // endregion
10699func (c * Client ) requestWithRetries (method , endpoint string , body , out interface {}) (* http.Response , error ) {
107100 var resp * http.Response
108101 var err error
@@ -188,7 +181,7 @@ func (c *Client) requestWithRetries(method, endpoint string, body, out interface
188181 return resp , response .HandleAPIErrorResponse (resp , c .Sugar )
189182}
190183
191- // executeRequest executes an HTTP request using the specified method, endpoint, and request body without implementing
184+ // requestNoRetries executes an HTTP request using the specified method, endpoint, and request body without implementing
192185// retry logic. It is primarily designed for non-idempotent HTTP methods like POST and PATCH, where the request should
193186// not be automatically retried within this function due to the potential side effects of re-submitting the same data.
194187// Parameters:
@@ -225,11 +218,9 @@ func (c *Client) requestNoRetries(method, endpoint string, body, out interface{}
225218 return nil , err
226219 }
227220
228- c .Sugar .Debug ("LOGHERE" )
229221 c .Sugar .Debugf ("Status Code: %v" , resp .StatusCode )
230222
231223 if resp .StatusCode >= http .StatusOK && resp .StatusCode < http .StatusBadRequest {
232- c .Sugar .Debug ("FLAG 1 - Request Considered Successful" )
233224 if resp .StatusCode == http .StatusPermanentRedirect || resp .StatusCode == http .StatusTemporaryRedirect {
234225 c .Sugar .Warn ("Redirect response received" , zap .Int ("status_code" , resp .StatusCode ), zap .String ("location" , resp .Header .Get ("Location" )))
235226 }
@@ -238,15 +229,12 @@ func (c *Client) requestNoRetries(method, endpoint string, body, out interface{}
238229 return resp , response .HandleAPISuccessResponse (resp , out , c .Sugar )
239230 }
240231
241- c .Sugar .Debug ("FLAG 2 - Request Considered NOT Successful" )
242-
243232 return nil , response .HandleAPIErrorResponse (resp , c .Sugar )
244233}
245234
246- // TODO function comment
235+ // request is a base leve private function which the contextual functions above utilise to make requests // TODO improve this comment probably.
247236func (c * Client ) request (ctx context.Context , method , endpoint string , body interface {}) (* http.Response , error ) {
248237
249- // TODO Concurrency - Refactor or remove this
250238 if c .config .EnableConcurrencyManagement {
251239 _ , requestID , err := c .Concurrency .AcquireConcurrencyPermit (ctx )
252240 if err != nil {
0 commit comments