Skip to content

Commit 70a94c0

Browse files
authored
Merge pull request #731 from huanggze/master
Improve API error handling
2 parents aa9238d + 8f87c69 commit 70a94c0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

api/prometheus/v1/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,14 +905,14 @@ func (h *apiClientImpl) Do(ctx context.Context, req *http.Request) (*http.Respon
905905
}
906906
}
907907

908-
if apiError(code) != (result.Status == "error") {
908+
if apiError(code) && result.Status == "success" {
909909
err = &Error{
910910
Type: ErrBadResponse,
911911
Msg: "inconsistent body for response code",
912912
}
913913
}
914914

915-
if apiError(code) && result.Status == "error" {
915+
if result.Status == "error" {
916916
err = &Error{
917917
Type: result.ErrorType,
918918
Msg: result.Error,

api/prometheus/v1/api_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,8 @@ func TestAPIClientDo(t *testing.T) {
10951095
Error: "timed out",
10961096
},
10971097
expectedErr: &Error{
1098-
Type: ErrBadResponse,
1099-
Msg: "inconsistent body for response code",
1098+
Type: ErrTimeout,
1099+
Msg: "timed out",
11001100
},
11011101
},
11021102
{
@@ -1109,8 +1109,8 @@ func TestAPIClientDo(t *testing.T) {
11091109
Warnings: []string{"a"},
11101110
},
11111111
expectedErr: &Error{
1112-
Type: ErrBadResponse,
1113-
Msg: "inconsistent body for response code",
1112+
Type: ErrTimeout,
1113+
Msg: "timed out",
11141114
},
11151115
expectedWarnings: []string{"a"},
11161116
},

0 commit comments

Comments
 (0)