Skip to content

Commit 85c720a

Browse files
committed
Refactor error handling in executeRequest function
1 parent 00faa68 commit 85c720a

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

httpclient/request.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ func (c *Client) executeRequest(method, endpoint string, body, out interface{})
352352
}
353353

354354
// Handle error responses for status codes outside the successful range
355-
return nil, c.handleErrorResponse(resp, out, log, method, endpoint)
355+
//return nil, c.handleErrorResponse(resp, out, log, method, endpoint)
356+
return nil, response.HandleAPIErrorResponse(resp, log)
356357
}
357358

358359
// do sends an HTTP request using the client's HTTP client. It logs the request and error details, if any,
@@ -378,20 +379,12 @@ func (c *Client) do(req *http.Request, log logger.Logger, method, endpoint strin
378379

379380
if err != nil {
380381
// Log the error with structured logging, including method, endpoint, and the error itself
381-
log.Error("Failed to send request",
382-
zap.String("method", method),
383-
zap.String("endpoint", endpoint),
384-
zap.Error(err),
385-
)
382+
log.Error("Failed to send request", zap.String("method", method), zap.String("endpoint", endpoint), zap.Error(err))
386383
return nil, err
387384
}
388385

389386
// Log the response status code for successful requests
390-
log.Debug("Request sent successfully",
391-
zap.String("method", method),
392-
zap.String("endpoint", endpoint),
393-
zap.Int("status_code", resp.StatusCode),
394-
)
387+
log.Debug("Request sent successfully", zap.String("method", method), zap.String("endpoint", endpoint), zap.Int("status_code", resp.StatusCode))
395388

396389
return resp, nil
397390
}

0 commit comments

Comments
 (0)