mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-12 00:35:03 +00:00
fix: additional logging in API client (#267)
This commit is contained in:
parent
696ecb05d8
commit
763527e535
@ -12,6 +12,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -54,22 +56,23 @@ func (c *VirtualEnvironmentClient) Authenticate(ctx context.Context, reset bool)
|
|||||||
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
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)
|
res, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
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)
|
err = c.ValidateResponseCode(res)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
resBody := VirtualEnvironmentAuthenticationResponseBody{}
|
resBody := VirtualEnvironmentAuthenticationResponseBody{}
|
||||||
err = json.NewDecoder(res.Body).Decode(&resBody)
|
err = json.NewDecoder(res.Body).Decode(&resBody)
|
||||||
|
|
||||||
if err != nil {
|
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 {
|
if resBody.Data == nil {
|
||||||
|
@ -180,6 +180,9 @@ func (c *VirtualEnvironmentClient) DoRequest(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tflog.Debug(ctx, "sending request", map[string]interface{}{
|
||||||
|
"path": req.URL.Path,
|
||||||
|
})
|
||||||
res, err := c.httpClient.Do(req)
|
res, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fErr := fmt.Errorf(
|
fErr := fmt.Errorf(
|
||||||
|
Loading…
Reference in New Issue
Block a user