From 32a545bf616b70a4302c266b6ca078cc56652dc1 Mon Sep 17 00:00:00 2001 From: johncming Date: Sat, 22 Aug 2020 19:32:48 +0800 Subject: [PATCH] Replace with the standard library constant. Signed-off-by: johncming --- api/prometheus/v1/api.go | 4 +--- api/prometheus/v1/api_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/api/prometheus/v1/api.go b/api/prometheus/v1/api.go index 6af67f5..549cc8d 100644 --- a/api/prometheus/v1/api.go +++ b/api/prometheus/v1/api.go @@ -117,8 +117,6 @@ func marshalPointJSONIsEmpty(ptr unsafe.Pointer) bool { } const ( - statusAPIError = 422 - apiPrefix = "/api/v1" epAlerts = apiPrefix + "/alerts" @@ -943,7 +941,7 @@ type apiResponse struct { func apiError(code int) bool { // These are the codes that Prometheus sends when it returns an error. - return code == statusAPIError || code == http.StatusBadRequest + return code == http.StatusUnprocessableEntity || code == http.StatusBadRequest } func errorTypeAndMsgFor(resp *http.Response) (ErrorType, string) { diff --git a/api/prometheus/v1/api_test.go b/api/prometheus/v1/api_test.go index 6a37c71..2107575 100644 --- a/api/prometheus/v1/api_test.go +++ b/api/prometheus/v1/api_test.go @@ -84,7 +84,7 @@ func (c *apiTestClient) Do(ctx context.Context, req *http.Request) (*http.Respon if test.inStatusCode != 0 { resp.StatusCode = test.inStatusCode } else if test.inErr != nil { - resp.StatusCode = statusAPIError + resp.StatusCode = http.StatusUnprocessableEntity } else { resp.StatusCode = http.StatusOK } @@ -1118,7 +1118,7 @@ func (c *testClient) Do(ctx context.Context, req *http.Request) (*http.Response, func TestAPIClientDo(t *testing.T) { tests := []apiClientTest{ { - code: statusAPIError, + code: http.StatusUnprocessableEntity, response: &apiResponse{ Status: "error", Data: json.RawMessage(`null`), @@ -1132,7 +1132,7 @@ func TestAPIClientDo(t *testing.T) { expectedBody: `null`, }, { - code: statusAPIError, + code: http.StatusUnprocessableEntity, response: &apiResponse{ Status: "error", Data: json.RawMessage(`"test"`), @@ -1177,7 +1177,7 @@ func TestAPIClientDo(t *testing.T) { }, }, { - code: statusAPIError, + code: http.StatusUnprocessableEntity, response: "bad json", expectedErr: &Error{ Type: ErrBadResponse, @@ -1185,7 +1185,7 @@ func TestAPIClientDo(t *testing.T) { }, }, { - code: statusAPIError, + code: http.StatusUnprocessableEntity, response: &apiResponse{ Status: "success", Data: json.RawMessage(`"test"`), @@ -1196,7 +1196,7 @@ func TestAPIClientDo(t *testing.T) { }, }, { - code: statusAPIError, + code: http.StatusUnprocessableEntity, response: &apiResponse{ Status: "success", Data: json.RawMessage(`"test"`),