@@ -532,12 +532,7 @@ func (c *Client) doRequest(ctx context.Context, method, endpoint string, params
532532 }
533533
534534 if c .debug && c .logger != nil {
535- loggedReq , logErr := c .logRequest (req )
536- if logErr != nil {
537- return logErr
538- }
539-
540- req = loggedReq
535+ req = c .logRequest (req )
541536 }
542537
543538 processResponse := func (start , end time.Time ) error {
@@ -573,6 +568,7 @@ func (c *Client) doRequest(ctx context.Context, method, endpoint string, params
573568 startTime := time .Now ()
574569 resp , err = c .sendRequest (req )
575570 endTime := time .Now ()
571+
576572 if err == nil {
577573 if err = processResponse (startTime , endTime ); err == nil {
578574 return nil
@@ -619,9 +615,7 @@ func (c *Client) shouldRetry(resp *http.Response, err error) bool {
619615}
620616
621617func (c * Client ) createRequest (ctx context.Context , method , endpoint string , params requestParams ) (* http.Request , error ) {
622- var (
623- bodyReader io.Reader
624- )
618+ var bodyReader io.Reader
625619
626620 if params .Body != nil {
627621 // Reset the body position to the start before using it
@@ -689,12 +683,13 @@ func redactHeaders(headers http.Header) http.Header {
689683 return redacted
690684}
691685
692- func (c * Client ) logRequest (req * http.Request ) ( * http.Request , error ) {
686+ func (c * Client ) logRequest (req * http.Request ) * http.Request {
693687 var reqBody bytes.Buffer
694688 if req .Body != nil {
695689 if _ , err := io .Copy (& reqBody , req .Body ); err != nil {
696690 c .logger .Errorf ("failed to read request body: %v" , err )
697691 }
692+
698693 req .Body = io .NopCloser (bytes .NewReader (reqBody .Bytes ()))
699694 }
700695
@@ -729,7 +724,7 @@ func (c *Client) logRequest(req *http.Request) (*http.Request, error) {
729724 c .logger .Debugf (logBuf .String ())
730725 }
731726
732- return req , nil
727+ return req
733728}
734729
735730func formatHeaders (headers map [string ][]string ) string {
@@ -740,11 +735,13 @@ func formatHeaders(headers map[string][]string) string {
740735 for key := range headers {
741736 keys = append (keys , key )
742737 }
738+
743739 sort .Strings (keys )
744740
745741 for _ , key := range keys {
746742 builder .WriteString (fmt .Sprintf (" %s: %s\n " , key , strings .Join (headers [key ], ", " )))
747743 }
744+
748745 return strings .TrimSuffix (builder .String (), "\n " )
749746}
750747
@@ -754,7 +751,8 @@ func formatBody(body string) (string, error) {
754751 return "" , nil
755752 }
756753
757- var jsonData map [string ]interface {}
754+ var jsonData map [string ]any
755+
758756 err := json .Unmarshal ([]byte (body ), & jsonData )
759757 if err != nil {
760758 return "" , fmt .Errorf ("error unmarshalling JSON: %w" , err )
@@ -773,7 +771,9 @@ func formatDate(dateStr string) (string, error) {
773771 if err != nil {
774772 return "" , fmt .Errorf ("error parsing date: %v" , err )
775773 }
774+
776775 formattedDate := parsedTime .In (time .Local ).Format ("2006-01-02T15:04:05-07:00" ) // nolint:gosmopolitan
776+
777777 return formattedDate , nil
778778}
779779
0 commit comments