From 67bf30dfa8bc7af07d693826314fe461467bd60e Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Mon, 11 Nov 2024 14:48:24 -0300 Subject: [PATCH] improve the error message when failing to download kots binaries --- pkg/replicatedapp/embeddedcluster.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/replicatedapp/embeddedcluster.go b/pkg/replicatedapp/embeddedcluster.go index 9481e0e18f..429eaf5e9e 100644 --- a/pkg/replicatedapp/embeddedcluster.go +++ b/pkg/replicatedapp/embeddedcluster.go @@ -71,7 +71,15 @@ func DownloadKOTSBinary(license *kotsv1beta1.License, versionLabel string) (stri defer resp.Body.Close() if resp.StatusCode != 200 { - return "", errors.Errorf("unexpected status code %d", resp.StatusCode) + if resp.Body != nil { + body, err := io.ReadAll(resp.Body) + if err != nil { + return "", errors.Wrapf(err, "failed to read body following unexpected status code %d", resp.StatusCode) + } + return "", errors.Errorf("unexpected status code %d: %s", resp.StatusCode, body) + } else { + return "", errors.Errorf("unexpected status code %d", resp.StatusCode) + } } tmpFile, err := os.CreateTemp("", "kotsbin")