From 887587ba6273055dda577ee8784e4c4fd64ff0e8 Mon Sep 17 00:00:00 2001 From: Moritz Sanft <58110325+msanft@users.noreply.github.com> Date: Fri, 7 Jun 2024 12:20:48 +0200 Subject: [PATCH] cli: return a more helpful error message on maa patch failure --- internal/maa/patch.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/maa/patch.go b/internal/maa/patch.go index 5dfed9435..d6dc2fd1d 100644 --- a/internal/maa/patch.go +++ b/internal/maa/patch.go @@ -9,6 +9,7 @@ import ( "context" "encoding/base64" "fmt" + "io" "net/http" "github.com/Azure/azure-sdk-for-go/profiles/latest/attestation/attestation" @@ -55,10 +56,14 @@ func (p AzurePolicyPatcher) Patch(ctx context.Context, attestationURL string) er if err != nil { return fmt.Errorf("sending request: %w", err) } - resp.Body.Close() + defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return fmt.Errorf("updating attestation policy: unexpected status code: %s", resp.Status) + body, err := io.ReadAll(resp.Body) + if err != nil { + return fmt.Errorf("updating attestation policy: unexpected status code: %s\nread response body: %w", resp.Status, err) + } + return fmt.Errorf("updating attestation policy: unexpected status code: %s\nresponse body: %s", resp.Status, string(body)) } return nil