diff --git a/authority/provisioner/webhook.go b/authority/provisioner/webhook.go index 407b84d83..69023bf6f 100644 --- a/authority/provisioner/webhook.go +++ b/authority/provisioner/webhook.go @@ -9,8 +9,10 @@ import ( "encoding/hex" "encoding/json" "fmt" + "io" "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 {