Skip to content

Commit

Permalink
Improve API error handling
Browse files Browse the repository at this point in the history
Signed-off-by: huanggze <loganhuang@yunify.com>
  • Loading branch information
huanggze committed Apr 2, 2020
1 parent aa9238d commit 8f87c69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions api/prometheus/v1/api.go
Expand Up @@ -905,14 +905,14 @@ func (h *apiClientImpl) Do(ctx context.Context, req *http.Request) (*http.Respon
}
}

if apiError(code) != (result.Status == "error") {
if apiError(code) && result.Status == "success" {
err = &Error{
Type: ErrBadResponse,
Msg: "inconsistent body for response code",
}
}

if apiError(code) && result.Status == "error" {
if result.Status == "error" {
err = &Error{
Type: result.ErrorType,
Msg: result.Error,
Expand Down
8 changes: 4 additions & 4 deletions api/prometheus/v1/api_test.go
Expand Up @@ -1095,8 +1095,8 @@ func TestAPIClientDo(t *testing.T) {
Error: "timed out",
},
expectedErr: &Error{
Type: ErrBadResponse,
Msg: "inconsistent body for response code",
Type: ErrTimeout,
Msg: "timed out",
},
},
{
Expand All @@ -1109,8 +1109,8 @@ func TestAPIClientDo(t *testing.T) {
Warnings: []string{"a"},
},
expectedErr: &Error{
Type: ErrBadResponse,
Msg: "inconsistent body for response code",
Type: ErrTimeout,
Msg: "timed out",
},
expectedWarnings: []string{"a"},
},
Expand Down

0 comments on commit 8f87c69

Please sign in to comment.