From 763527e53584e8121b1138830ad97e8e89780322 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sat, 18 Mar 2023 21:15:19 -0400 Subject: [PATCH] fix: additional logging in API client (#267) --- proxmox/virtual_environment_authentication.go | 11 +++++++---- proxmox/virtual_environment_client.go | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/proxmox/virtual_environment_authentication.go b/proxmox/virtual_environment_authentication.go index c31f5cd0..f8572eb3 100644 --- a/proxmox/virtual_environment_authentication.go +++ b/proxmox/virtual_environment_authentication.go @@ -12,6 +12,8 @@ import ( "fmt" "net/http" "net/url" + + "github.com/hashicorp/terraform-plugin-log/tflog" ) const ( @@ -54,22 +56,23 @@ func (c *VirtualEnvironmentClient) Authenticate(ctx context.Context, reset bool) req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + tflog.Debug(ctx, "sending authentication request", map[string]interface{}{ + "path": req.URL.Path, + }) res, err := c.httpClient.Do(req) if err != nil { - return errors.New("failed to retrieve authentication response") + return fmt.Errorf("failed to retrieve authentication response: %w", err) } err = c.ValidateResponseCode(res) - if err != nil { return err } resBody := VirtualEnvironmentAuthenticationResponseBody{} err = json.NewDecoder(res.Body).Decode(&resBody) - if err != nil { - return errors.New("failed to decode authentication response") + return fmt.Errorf("failed to decode authentication response, %w", err) } if resBody.Data == nil { diff --git a/proxmox/virtual_environment_client.go b/proxmox/virtual_environment_client.go index 75f4a15a..7746728b 100644 --- a/proxmox/virtual_environment_client.go +++ b/proxmox/virtual_environment_client.go @@ -180,6 +180,9 @@ func (c *VirtualEnvironmentClient) DoRequest( return err } + tflog.Debug(ctx, "sending request", map[string]interface{}{ + "path": req.URL.Path, + }) res, err := c.httpClient.Do(req) if err != nil { fErr := fmt.Errorf(