From 866ca4e307b52e3090e3ecfa2e4a99d5e3d4f81c Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Thu, 2 Sep 2021 09:26:16 +0200 Subject: [PATCH] added additional debug logging --- api/client.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/api/client.go b/api/client.go index 5a6919d..2a7833d 100644 --- a/api/client.go +++ b/api/client.go @@ -83,6 +83,7 @@ func (c *Client) newRequest(method, path string, body interface{}) (*http.Reques return nil, fmt.Errorf("Parsing URL: %w", err) } u := c.baseURL.ResolveReference(rel) + var buf io.ReadWriter if body != nil { buf = new(bytes.Buffer) @@ -104,6 +105,15 @@ func (c *Client) newRequest(method, path string, body interface{}) (*http.Reques req.AddCookie(&c.sessionToken) req.AddCookie(&c.csrfToken) + // Debugging + c.log("Request URL: %v", req.URL.String()) + if c.Debug && body != nil { + data, err := json.Marshal(body) + if err == nil { + c.log("Raw Request: %v", string(data)) + } + } + return req, nil } @@ -127,6 +137,8 @@ func (c *Client) do(ctx context.Context, req *http.Request, v *APIResponse) (*ht return resp, fmt.Errorf("Error Reading Resopnse Body: %w", err) } + c.log("Raw Response: %v", string(bodyBytes)) + err = json.Unmarshal(bodyBytes, v) if err != nil { return resp, fmt.Errorf("Unable to Parse JSON API Response with HTTP Status Code %v: %w", resp.StatusCode, err)