Make sure body is properly printed when status code not equals 200

This commit is contained in:
Mads Jon Nielsen 2024-04-23 09:00:39 +02:00
parent d094e52bd1
commit 2941825577
1 changed files with 8 additions and 2 deletions

View File

@ -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
}