Skip to content

Replace with the standard library constant. #793

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

Merged
merged 1 commit into from
Aug 25, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions api/prometheus/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ func marshalPointJSONIsEmpty(ptr unsafe.Pointer) bool {
}

const (
statusAPIError = 422

apiPrefix = "/api/v1"

epAlerts = apiPrefix + "/alerts"
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions api/prometheus/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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`),
Expand All @@ -1132,7 +1132,7 @@ func TestAPIClientDo(t *testing.T) {
expectedBody: `null`,
},
{
code: statusAPIError,
code: http.StatusUnprocessableEntity,
response: &apiResponse{
Status: "error",
Data: json.RawMessage(`"test"`),
Expand Down Expand Up @@ -1177,15 +1177,15 @@ func TestAPIClientDo(t *testing.T) {
},
},
{
code: statusAPIError,
code: http.StatusUnprocessableEntity,
response: "bad json",
expectedErr: &Error{
Type: ErrBadResponse,
Msg: "readObjectStart: expect { or n, but found b, error found in #1 byte of ...|bad json|..., bigger context ...|bad json|...",
},
},
{
code: statusAPIError,
code: http.StatusUnprocessableEntity,
response: &apiResponse{
Status: "success",
Data: json.RawMessage(`"test"`),
Expand All @@ -1196,7 +1196,7 @@ func TestAPIClientDo(t *testing.T) {
},
},
{
code: statusAPIError,
code: http.StatusUnprocessableEntity,
response: &apiResponse{
Status: "success",
Data: json.RawMessage(`"test"`),
Expand Down