From 2941825577186689988a24a7a8bad0bb2f554755 Mon Sep 17 00:00:00 2001 From: Mads Jon Nielsen Date: Tue, 23 Apr 2024 09:00:39 +0200 Subject: [PATCH] Make sure body is properly printed when status code not equals 200 --- cmd/cloudflared/tunnel/subcommands.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/cloudflared/tunnel/subcommands.go b/cmd/cloudflared/tunnel/subcommands.go index 14f6bd3d..20604290 100644 --- a/cmd/cloudflared/tunnel/subcommands.go +++ b/cmd/cloudflared/tunnel/subcommands.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "io" "net/http" "os" "path/filepath" @@ -411,13 +412,18 @@ func buildReadyCommand() *cli.Command { } func readyCommand(c *cli.Context) error { - requestURL := fmt.Sprintf("http://%s/ready", c.String("metrics")) + metricsOpts := c.String("metrics") + requestURL := fmt.Sprintf("http://%s/ready", metricsOpts) res, err := http.Get(requestURL) if err != nil { return err } if res.StatusCode != 200 { - return fmt.Errorf("/ready endpoint returned status code %d\n%s", res.StatusCode, res.Body) + body, err := io.ReadAll(res.Body) + if err != nil { + return err + } + return fmt.Errorf("http://%s/ready endpoint returned status code %d\n%s", metricsOpts, res.StatusCode, body) } return nil }