Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve API error handling #731

Merged
merged 1 commit into from Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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