Skip to content

Commit

Permalink
Return the response status if body is empty in sensuctl (#2472)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Plourde <[email protected]>
  • Loading branch information
palourde authored Dec 3, 2018
1 parent 4b18f6d commit 419c199
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ period of disconnection from the backend.
- A panic in keepalive/check ttl monitors causing a panic.
- Monitors are now properly namespaced in etcd.
- Updating a users groups will no longer corrupt their password
- Prevent empty error messages in sensuctl.
- Fixed a bug where keepalive failures could be influenced by check TTL
successes, and vice versa.
- Fixed a bug where check TTL events were not formed correctly.
Expand Down
8 changes: 7 additions & 1 deletion cli/client/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"encoding/json"
"fmt"

"github.com/go-resty/resty"
)
Expand All @@ -21,7 +22,12 @@ func (a APIError) Error() string {
func UnmarshalError(res *resty.Response) error {
var apiErr APIError
if err := json.Unmarshal(res.Body(), &apiErr); err != nil {
apiErr.Message = string(res.Body())
if len(res.Body()) > 0 {
apiErr.Message = string(res.Body())
} else {
apiErr.Message = fmt.Sprintf("the API returned: %s", res.Status())
}
}

return apiErr
}

0 comments on commit 419c199

Please sign in to comment.