Skip to content

Commit a2bb752

Browse files
committed
updated error handling to return non-zero exit code for failed http call
1 parent d7a7dbb commit a2bb752

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

pkg/cmd/api/api.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package api
33
import (
44
"bytes"
55
"encoding/json"
6+
"errors"
67
"io"
78
"net/http"
89
"os"
@@ -62,6 +63,10 @@ func apiRun(cmd *cobra.Command, f factory.Factory, path string) error {
6263
return err
6364
}
6465

66+
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
67+
return errors.New(string(body))
68+
}
69+
6570
// Pretty-print if valid JSON, otherwise output raw
6671
var prettyJSON bytes.Buffer
6772
if err := json.Indent(&prettyJSON, body, "", " "); err == nil {
@@ -70,9 +75,5 @@ func apiRun(cmd *cobra.Command, f factory.Factory, path string) error {
7075
cmd.Print(string(body))
7176
}
7277

73-
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
74-
OsExit(resp.StatusCode)
75-
}
76-
7778
return nil
7879
}

0 commit comments

Comments
 (0)