Replace with the standard library constant.

Signed-off-by: johncming <johncming@yahoo.com>
This commit is contained in:
johncming 2020-08-22 19:32:48 +08:00
parent aea1b33289
commit 32a545bf61
2 changed files with 7 additions and 9 deletions

View File

@ -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) {

View File

@ -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"`),