server: fixed error message handling
This commit is contained in:
parent
cccf6321cc
commit
34bbd1ce85
2 changed files with 30 additions and 17 deletions
12
cmd/fetch.go
12
cmd/fetch.go
|
|
@ -24,6 +24,11 @@ var fetchCmd = &cobra.Command{
|
|||
return
|
||||
}
|
||||
|
||||
// check if we actually have any targets to run
|
||||
if len(targets) <= 0 {
|
||||
log.Error().Msg("must specify a target")
|
||||
}
|
||||
|
||||
// check to see if an access token is available from env
|
||||
if conf.AccessToken == "" {
|
||||
// check if OCHAMI_ACCESS_TOKEN env var is set if no access token is provided and use that instead
|
||||
|
|
@ -49,14 +54,13 @@ var fetchCmd = &cobra.Command{
|
|||
url := fmt.Sprintf("%s/generate?target=%s", remoteHost, target)
|
||||
res, body, err := util.MakeRequest(url, http.MethodGet, nil, headers)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to make request")
|
||||
log.Error().Err(err).Msg("failed to fetch files")
|
||||
return
|
||||
}
|
||||
// handle getting other error codes other than a 200
|
||||
if res != nil {
|
||||
if res.StatusCode == http.StatusOK {
|
||||
log.Info().Msgf("%s\n", string(body))
|
||||
}
|
||||
// NOTE: the server responses are already marshaled to JSON
|
||||
fmt.Print(string(body))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue