Skip to content

Commit

Permalink
fix: additional logging in API client (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpg authored Mar 19, 2023
1 parent 696ecb0 commit 763527e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 7 additions & 4 deletions proxmox/virtual_environment_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"fmt"
"net/http"
"net/url"

"github.com/hashicorp/terraform-plugin-log/tflog"
)

const (
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions proxmox/virtual_environment_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 763527e

Please sign in to comment.