From 0c4b9e94333ac64cf52c58895adc6153efd2b2d7 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Thu, 7 Nov 2024 15:47:22 +0000 Subject: [PATCH] Improve error handling for metering command Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- cmd/metering.go | 3 +-- pkg/client.go | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/metering.go b/cmd/metering.go index 8f7d0b7..8b85a3b 100644 --- a/cmd/metering.go +++ b/cmd/metering.go @@ -74,12 +74,11 @@ func runMeteringE(cmd *cobra.Command, args []string) error { c := pkg.NewClient(http.DefaultClient, os.Getenv("ACTUATED_URL")) res, status, err := c.GetMetering(pat, owner, host, id, staff) - if err != nil { return err } - if status != http.StatusAccepted { + if status != http.StatusAccepted && status != http.StatusOK { return fmt.Errorf("unexpected status code: %d, body: %s", status, res) } diff --git a/pkg/client.go b/pkg/client.go index 23bb7d2..703d618 100644 --- a/pkg/client.go +++ b/pkg/client.go @@ -346,6 +346,11 @@ func (c *Client) GetMetering(patStr, owner, host, id string, staff bool) (string body, _ = io.ReadAll(res.Body) } + if res.StatusCode != http.StatusOK && + res.StatusCode != http.StatusAccepted { + return string(body), res.StatusCode, nil + } + var prettyJSON bytes.Buffer if err = json.Indent(&prettyJSON, []byte(body), "", " "); err != nil {