server: fixed error message handling

This commit is contained in:
David Allen 2024-12-16 15:24:52 -07:00
parent cccf6321cc
commit 34bbd1ce85
Signed by: towk
GPG key ID: 793B2924A49B3A3F
2 changed files with 30 additions and 17 deletions

View file

@ -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))
}
}
},