Skip to content

Commit 0c4b9e9

Browse files
committed
Improve error handling for metering command
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 40ac180 commit 0c4b9e9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

cmd/metering.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,11 @@ func runMeteringE(cmd *cobra.Command, args []string) error {
7474
c := pkg.NewClient(http.DefaultClient, os.Getenv("ACTUATED_URL"))
7575

7676
res, status, err := c.GetMetering(pat, owner, host, id, staff)
77-
7877
if err != nil {
7978
return err
8079
}
8180

82-
if status != http.StatusAccepted {
81+
if status != http.StatusAccepted && status != http.StatusOK {
8382
return fmt.Errorf("unexpected status code: %d, body: %s", status, res)
8483
}
8584

pkg/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ func (c *Client) GetMetering(patStr, owner, host, id string, staff bool) (string
346346
body, _ = io.ReadAll(res.Body)
347347
}
348348

349+
if res.StatusCode != http.StatusOK &&
350+
res.StatusCode != http.StatusAccepted {
351+
return string(body), res.StatusCode, nil
352+
}
353+
349354
var prettyJSON bytes.Buffer
350355

351356
if err = json.Indent(&prettyJSON, []byte(body), "", " "); err != nil {

0 commit comments

Comments
 (0)