Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"
"time"

log "github.com/sirupsen/logrus"
resty "github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
)

// RawJSON controls if the client does json handling or outputs it raw
Expand All @@ -21,11 +21,15 @@ func GenericJSONErrorHandling(resp *resty.Response, err error) (*resty.Response,
// Handle known error codes as well as error codes which Supervisor returns without
// a (JSON) body.
switch resp.StatusCode() {
case http.StatusOK, http.StatusBadRequest, http.StatusNotFound, http.StatusServiceUnavailable:
case http.StatusOK, http.StatusBadRequest, http.StatusNotFound, http.StatusServiceUnavailable, http.StatusTooManyRequests:
// Success and these errors should have JSON responses
if !resty.IsJSONType(resp.Header().Get("Content-Type")) {
return nil, fmt.Errorf("unexpected non-JSON response (status: %d)", resp.StatusCode())
}
case http.StatusInternalServerError:
if !resty.IsJSONType(resp.Header().Get("Content-Type")) {
return nil, fmt.Errorf("unknown error occurred, check supervisor logs with 'ha supervisor logs")
}
Comment thread
sairon marked this conversation as resolved.
case http.StatusUnauthorized:
if !resty.IsJSONType(resp.Header().Get("Content-Type")) {
return nil, fmt.Errorf("unauthorized: missing or invalid API token")
Expand Down