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)