@@ -115,15 +115,14 @@ func (c *Client) DoRequest(method, endpoint string, body, out interface{}) (*htt
115115// endregion
116116func (c * Client ) executeRequestWithRetries (method , endpoint string , body , out interface {}) (* http.Response , error ) {
117117 // TODO review refactor executeRequestWithRetries
118- log := c .Logger
119118 ctx := context .Background ()
120119 totalRetryDeadline := time .Now ().Add (c .config .TotalRetryDuration )
121120
122121 var resp * http.Response
123122 var err error
124123 var retryCount int
125124
126- log .Debug ("Executing request with retries" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ))
125+ c . Sugar .Debug ("Executing request with retries" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ))
127126
128127 for time .Now ().Before (totalRetryDeadline ) {
129128 res , requestErr := c .doRequest (ctx , method , endpoint , body )
@@ -134,22 +133,22 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
134133
135134 if resp .StatusCode >= 200 && resp .StatusCode < 400 {
136135 if resp .StatusCode >= 300 {
137- log .Warn ("Redirect response received" , zap .Int ("status_code" , resp .StatusCode ), zap .String ("location" , resp .Header .Get ("Location" )))
136+ c . Sugar .Warn ("Redirect response received" , zap .Int ("status_code" , resp .StatusCode ), zap .String ("location" , resp .Header .Get ("Location" )))
138137 }
139- return resp , response .HandleAPISuccessResponse (resp , out , log )
138+ return resp , response .HandleAPISuccessResponse (resp , out , c . Sugar )
140139 }
141140
142141 statusMessage := status .TranslateStatusCode (resp )
143142
144143 if resp != nil && status .IsNonRetryableStatusCode (resp ) {
145- log .Warn ("Non-retryable error received" , zap .Int ("status_code" , resp .StatusCode ), zap .String ("status_message" , statusMessage ))
146- return resp , response .HandleAPIErrorResponse (resp , log )
144+ c . Sugar .Warn ("Non-retryable error received" , zap .Int ("status_code" , resp .StatusCode ), zap .String ("status_message" , statusMessage ))
145+ return resp , response .HandleAPIErrorResponse (resp , c . Sugar )
147146 }
148147
149148 if status .IsRateLimitError (resp ) {
150- waitDuration := ratehandler .ParseRateLimitHeaders (resp , log )
149+ waitDuration := ratehandler .ParseRateLimitHeaders (resp , c . Sugar )
151150 if waitDuration > 0 {
152- log .Warn ("Rate limit encountered, waiting before retrying" , zap .Duration ("waitDuration" , waitDuration ))
151+ c . Sugar .Warn ("Rate limit encountered, waiting before retrying" , zap .Duration ("waitDuration" , waitDuration ))
153152 time .Sleep (waitDuration )
154153 continue
155154 }
@@ -158,17 +157,17 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
158157 if status .IsTransientError (resp ) {
159158 retryCount ++
160159 if retryCount > c .config .MaxRetryAttempts {
161- log .Warn ("Max retry attempts reached" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ))
160+ c . Sugar .Warn ("Max retry attempts reached" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ))
162161 break
163162 }
164163 waitDuration := ratehandler .CalculateBackoff (retryCount )
165- log .Warn ("Retrying request due to transient error" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Int ("retryCount" , retryCount ), zap .Duration ("waitDuration" , waitDuration ), zap .Error (err ))
164+ c . Sugar .Warn ("Retrying request due to transient error" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Int ("retryCount" , retryCount ), zap .Duration ("waitDuration" , waitDuration ), zap .Error (err ))
166165 time .Sleep (waitDuration )
167166 continue
168167 }
169168
170169 if ! status .IsRetryableStatusCode (resp .StatusCode ) {
171- if apiErr := response .HandleAPIErrorResponse (resp , log ); apiErr != nil {
170+ if apiErr := response .HandleAPIErrorResponse (resp , c . Sugar ); apiErr != nil {
172171 err = apiErr
173172 }
174173 break
@@ -179,7 +178,7 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
179178 return nil , err
180179 }
181180
182- return resp , response .HandleAPIErrorResponse (resp , log )
181+ return resp , response .HandleAPIErrorResponse (resp , c . Sugar )
183182}
184183
185184// region comment
@@ -216,10 +215,10 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
216215// endregion
217216func (c * Client ) executeRequest (method , endpoint string , body , out interface {}) (* http.Response , error ) {
218217 // TODO review refactor execute Request
219- log := c . Logger
218+
220219 ctx := context .Background ()
221220
222- log .Debug ("Executing request without retries" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ))
221+ c . Sugar .Debug ("Executing request without retries" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ))
223222
224223 res , err := c .doRequest (ctx , method , endpoint , body )
225224 if err != nil {
@@ -228,12 +227,12 @@ func (c *Client) executeRequest(method, endpoint string, body, out interface{})
228227
229228 if res .StatusCode >= 200 && res .StatusCode < 400 {
230229 if res .StatusCode >= 300 {
231- log .Warn ("Redirect response received" , zap .Int ("status_code" , res .StatusCode ), zap .String ("location" , res .Header .Get ("Location" )))
230+ c . Sugar .Warn ("Redirect response received" , zap .Int ("status_code" , res .StatusCode ), zap .String ("location" , res .Header .Get ("Location" )))
232231 }
233- return res , response .HandleAPISuccessResponse (res , out , log )
232+ return res , response .HandleAPISuccessResponse (res , out , c . Sugar )
234233 }
235234
236- return nil , response .HandleAPIErrorResponse (res , log )
235+ return nil , response .HandleAPIErrorResponse (res , c . Sugar )
237236}
238237
239238func (c * Client ) doRequest (ctx context.Context , method , endpoint string , body interface {}) (* http.Response , error ) {
@@ -280,7 +279,7 @@ func (c *Client) doRequest(ctx context.Context, method, endpoint string, body in
280279
281280 resp , err := c .http .Do (req )
282281 if err != nil {
283- c .Logger .Error ("Failed to send request" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Error (err ))
282+ c .Sugar .Error ("Failed to send request" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Error (err ))
284283 return nil , err
285284 }
286285
@@ -292,9 +291,9 @@ func (c *Client) doRequest(ctx context.Context, method, endpoint string, body in
292291
293292 // TODO review LogCookies
294293
295- CheckDeprecationHeader (resp , c .Logger )
294+ CheckDeprecationHeader (resp , c .Sugar )
296295
297- c .Logger .Debug ("Request sent successfully" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Int ("status_code" , resp .StatusCode ))
296+ c .Sugar .Debug ("Request sent successfully" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Int ("status_code" , resp .StatusCode ))
298297
299298 time .Sleep (c .config .MandatoryRequestDelay )
300299
0 commit comments