forked from mirror/client_golang
Merge pull request #793 from johncming/stdlib-constant
Replace with the standard library constant.
This commit is contained in:
commit
4675060215
|
@ -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) {
|
||||
|
|
|
@ -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"`),
|
||||
|
|
Loading…
Reference in New Issue