Skip to content

Commit

Permalink
Improve error handling for metering command
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Nov 7, 2024
1 parent 40ac180 commit 0c4b9e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cmd/metering.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0c4b9e9

Please sign in to comment.