Skip to content

Commit

Permalink
chore: remove this body parsing, as it destroys the original body.
Browse files Browse the repository at this point in the history
  • Loading branch information
kashalls committed Sep 16, 2024
1 parent 8c54ef4 commit 1a82120
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions internal/unifi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,7 @@ func (c *httpClient) doRequest(method, path string, body io.Reader) (*http.Respo
c.csrf = csrf
}

bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Error("Failed to read response body", zap.Error(err))
return resp, nil
}
bodyString := string(bodyBytes)

log.With(zap.String("req_method", method), zap.String("req_path", path), zap.Int("req_code", resp.StatusCode), zap.String("req_body", bodyString)).Debug("Returned Request")
log.With(zap.String("req_method", method), zap.String("req_path", path), zap.Int("req_code", resp.StatusCode)).Debug("Returned Request")

// If the status code is 401, re-login and retry the request
if resp.StatusCode == http.StatusUnauthorized {
Expand Down Expand Up @@ -160,7 +153,7 @@ func (c *httpClient) GetEndpoints() ([]DNSRecord, error) {

var records []DNSRecord
if err = json.NewDecoder(resp.Body).Decode(&records); err != nil {
log.With(zap.Error(err), zap.String("req_url", url), zap.Any("req_body", resp.Body)).Debug("JSON Encoding Error")
log.With(zap.Error(err), zap.String("req_url", url), zap.Any("req_body", resp.Body)).Debug("Endpoint JSON Decoding Error")
return nil, err
}

Expand Down

0 comments on commit 1a82120

Please # to comment.