From 12bb5d16a4ff81710b73bb5ee9ffc09135f366d2 Mon Sep 17 00:00:00 2001 From: Josh Drake Date: Fri, 25 Aug 2023 12:56:06 -0500 Subject: [PATCH 1/2] Include webhook response in error message. --- authority/provisioner/webhook.go | 8 +++++++- authority/provisioner/webhook_test.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/authority/provisioner/webhook.go b/authority/provisioner/webhook.go index 407b84d83..f1eab5204 100644 --- a/authority/provisioner/webhook.go +++ b/authority/provisioner/webhook.go @@ -8,9 +8,11 @@ import ( "encoding/base64" "encoding/hex" "encoding/json" + "io" "fmt" "log" "net/http" + "strings" "text/template" "time" @@ -219,7 +221,11 @@ retry: goto retry } if resp.StatusCode >= 400 { - return nil, fmt.Errorf("Webhook server responded with %d", resp.StatusCode) + b, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("Webhook server responded with %d", resp.StatusCode) + } + return nil, fmt.Errorf("Webhook server responded with %d: %s", resp.StatusCode, strings.TrimSpace(string(b))) } respBody := &webhook.ResponseBody{} diff --git a/authority/provisioner/webhook_test.go b/authority/provisioner/webhook_test.go index 656d75d86..4c358130d 100644 --- a/authority/provisioner/webhook_test.go +++ b/authority/provisioner/webhook_test.go @@ -465,7 +465,7 @@ func TestWebhook_Do(t *testing.T) { }, errStatusCode: 404, serverErrMsg: "item not found", - expectErr: errors.New("Webhook server responded with 404"), + expectErr: errors.New("Webhook server responded with 404: item not found"), }, } for name, tc := range tests { From 6ee9035b17d2d921697a8b6a640610ac47e46b4d Mon Sep 17 00:00:00 2001 From: Josh Drake Date: Fri, 25 Aug 2023 13:14:10 -0500 Subject: [PATCH 2/2] Lint. --- authority/provisioner/webhook.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/authority/provisioner/webhook.go b/authority/provisioner/webhook.go index f1eab5204..69023bf6f 100644 --- a/authority/provisioner/webhook.go +++ b/authority/provisioner/webhook.go @@ -8,8 +8,8 @@ import ( "encoding/base64" "encoding/hex" "encoding/json" - "io" "fmt" + "io" "log" "net/http" "strings"