From f525f1cac6efb2159f2191ef6334dd4f7d08d7d0 Mon Sep 17 00:00:00 2001 From: huanggze Date: Thu, 2 Apr 2020 14:36:37 +0800 Subject: [PATCH] Improve error handling Signed-off-by: huanggze --- api/prometheus/v1/api.go | 4 ++-- api/prometheus/v1/api_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/prometheus/v1/api.go b/api/prometheus/v1/api.go index 61f7fb4cb..4a5fc171f 100644 --- a/api/prometheus/v1/api.go +++ b/api/prometheus/v1/api.go @@ -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, diff --git a/api/prometheus/v1/api_test.go b/api/prometheus/v1/api_test.go index 79b00a9de..b36c380c7 100644 --- a/api/prometheus/v1/api_test.go +++ b/api/prometheus/v1/api_test.go @@ -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", }, }, { @@ -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"}, },