@@ -66,13 +66,13 @@ import (
66
66
67
67
func (c * Client ) DoRequest (method , endpoint string , body , out interface {}) (* http.Response , error ) {
68
68
if ! c .config .RetryEligiableRequests {
69
- return c .executeRequest (method , endpoint , body , out )
69
+ return c .request (method , endpoint , body , out )
70
70
}
71
71
72
72
if IsIdempotentHTTPMethod (method ) {
73
- return c .executeRequestWithRetries (method , endpoint , body )
73
+ return c .requestWithRetries (method , endpoint , body )
74
74
} else if ! IsIdempotentHTTPMethod (method ) {
75
- return c .executeRequest (method , endpoint , body , out )
75
+ return c .request (method , endpoint , body , out )
76
76
} else {
77
77
return nil , fmt .Errorf ("unsupported http method: %s" , method )
78
78
}
@@ -112,7 +112,7 @@ func (c *Client) DoRequest(method, endpoint string, body, out interface{}) (*htt
112
112
// operations.
113
113
// - The retry mechanism employs exponential backoff with jitter to mitigate the impact of retries on the server.
114
114
// endregion
115
- func (c * Client ) executeRequestWithRetries (method , endpoint string , body interface {}) (* http.Response , error ) {
115
+ func (c * Client ) requestWithRetries (method , endpoint string , body interface {}) (* http.Response , error ) {
116
116
var resp * http.Response
117
117
var err error
118
118
var retryCount int
@@ -226,26 +226,27 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body interfa
226
226
// any errors encountered.
227
227
//
228
228
// endregion
229
- func (c * Client ) executeRequest (method , endpoint string , body , out interface {}) (* http.Response , error ) {
229
+ func (c * Client ) request (method , endpoint string , body , out interface {}) (* http.Response , error ) {
230
230
// TODO review refactor execute Request
231
231
232
232
ctx := context .Background ()
233
233
234
234
c .Sugar .Debug ("Executing request without retries" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ))
235
235
236
- res , err := c .doRequest (ctx , method , endpoint , body )
236
+ resp , err := c .doRequest (ctx , method , endpoint , body )
237
237
if err != nil {
238
238
return nil , err
239
239
}
240
240
241
- if res .StatusCode >= 200 && res .StatusCode < 400 {
242
- if res .StatusCode >= 300 {
243
- c .Sugar .Warn ("Redirect response received" , zap .Int ("status_code" , res .StatusCode ), zap .String ("location" , res .Header .Get ("Location" )))
241
+ if resp .StatusCode >= http . StatusOK && resp .StatusCode < http . StatusBadRequest {
242
+ if resp .StatusCode == http . StatusPermanentRedirect || resp . StatusCode == http . StatusTemporaryRedirect {
243
+ c .Sugar .Warn ("Redirect response received" , zap .Int ("status_code" , resp .StatusCode ), zap .String ("location" , resp .Header .Get ("Location" )))
244
244
}
245
- return res , response .HandleAPISuccessResponse (res , out , c .Sugar )
245
+ c .Sugar .Infof ("%s request successful at %v" , resp .Request .Method , resp .Request .URL )
246
+ return resp , nil
246
247
}
247
248
248
- return nil , response .HandleAPIErrorResponse (res , c .Sugar )
249
+ return nil , response .HandleAPIErrorResponse (resp , c .Sugar )
249
250
}
250
251
251
252
func (c * Client ) doRequest (ctx context.Context , method , endpoint string , body interface {}) (* http.Response , error ) {
0 commit comments