Merge pull request #793 from johncming/stdlib-constant

Replace with the standard library constant.
This commit is contained in:
Björn Rabenstein 2020-08-25 21:35:43 +02:00 committed by GitHub
commit 4675060215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View File

@ -117,8 +117,6 @@ func marshalPointJSONIsEmpty(ptr unsafe.Pointer) bool {
} }
const ( const (
statusAPIError = 422
apiPrefix = "/api/v1" apiPrefix = "/api/v1"
epAlerts = apiPrefix + "/alerts" epAlerts = apiPrefix + "/alerts"
@ -943,7 +941,7 @@ type apiResponse struct {
func apiError(code int) bool { func apiError(code int) bool {
// These are the codes that Prometheus sends when it returns an error. // 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) { func errorTypeAndMsgFor(resp *http.Response) (ErrorType, string) {

View File

@ -84,7 +84,7 @@ func (c *apiTestClient) Do(ctx context.Context, req *http.Request) (*http.Respon
if test.inStatusCode != 0 { if test.inStatusCode != 0 {
resp.StatusCode = test.inStatusCode resp.StatusCode = test.inStatusCode
} else if test.inErr != nil { } else if test.inErr != nil {
resp.StatusCode = statusAPIError resp.StatusCode = http.StatusUnprocessableEntity
} else { } else {
resp.StatusCode = http.StatusOK 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) { func TestAPIClientDo(t *testing.T) {
tests := []apiClientTest{ tests := []apiClientTest{
{ {
code: statusAPIError, code: http.StatusUnprocessableEntity,
response: &apiResponse{ response: &apiResponse{
Status: "error", Status: "error",
Data: json.RawMessage(`null`), Data: json.RawMessage(`null`),
@ -1132,7 +1132,7 @@ func TestAPIClientDo(t *testing.T) {
expectedBody: `null`, expectedBody: `null`,
}, },
{ {
code: statusAPIError, code: http.StatusUnprocessableEntity,
response: &apiResponse{ response: &apiResponse{
Status: "error", Status: "error",
Data: json.RawMessage(`"test"`), Data: json.RawMessage(`"test"`),
@ -1177,7 +1177,7 @@ func TestAPIClientDo(t *testing.T) {
}, },
}, },
{ {
code: statusAPIError, code: http.StatusUnprocessableEntity,
response: "bad json", response: "bad json",
expectedErr: &Error{ expectedErr: &Error{
Type: ErrBadResponse, Type: ErrBadResponse,
@ -1185,7 +1185,7 @@ func TestAPIClientDo(t *testing.T) {
}, },
}, },
{ {
code: statusAPIError, code: http.StatusUnprocessableEntity,
response: &apiResponse{ response: &apiResponse{
Status: "success", Status: "success",
Data: json.RawMessage(`"test"`), Data: json.RawMessage(`"test"`),
@ -1196,7 +1196,7 @@ func TestAPIClientDo(t *testing.T) {
}, },
}, },
{ {
code: statusAPIError, code: http.StatusUnprocessableEntity,
response: &apiResponse{ response: &apiResponse{
Status: "success", Status: "success",
Data: json.RawMessage(`"test"`), Data: json.RawMessage(`"test"`),