Skip to content

Commit 4675060

Browse files
authored
Merge pull request #793 from johncming/stdlib-constant
Replace with the standard library constant.
2 parents aea1b33 + 32a545b commit 4675060

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

api/prometheus/v1/api.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ func marshalPointJSONIsEmpty(ptr unsafe.Pointer) bool {
117117
}
118118

119119
const (
120-
statusAPIError = 422
121-
122120
apiPrefix = "/api/v1"
123121

124122
epAlerts = apiPrefix + "/alerts"
@@ -943,7 +941,7 @@ type apiResponse struct {
943941

944942
func apiError(code int) bool {
945943
// These are the codes that Prometheus sends when it returns an error.
946-
return code == statusAPIError || code == http.StatusBadRequest
944+
return code == http.StatusUnprocessableEntity || code == http.StatusBadRequest
947945
}
948946

949947
func errorTypeAndMsgFor(resp *http.Response) (ErrorType, string) {

api/prometheus/v1/api_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (c *apiTestClient) Do(ctx context.Context, req *http.Request) (*http.Respon
8484
if test.inStatusCode != 0 {
8585
resp.StatusCode = test.inStatusCode
8686
} else if test.inErr != nil {
87-
resp.StatusCode = statusAPIError
87+
resp.StatusCode = http.StatusUnprocessableEntity
8888
} else {
8989
resp.StatusCode = http.StatusOK
9090
}
@@ -1118,7 +1118,7 @@ func (c *testClient) Do(ctx context.Context, req *http.Request) (*http.Response,
11181118
func TestAPIClientDo(t *testing.T) {
11191119
tests := []apiClientTest{
11201120
{
1121-
code: statusAPIError,
1121+
code: http.StatusUnprocessableEntity,
11221122
response: &apiResponse{
11231123
Status: "error",
11241124
Data: json.RawMessage(`null`),
@@ -1132,7 +1132,7 @@ func TestAPIClientDo(t *testing.T) {
11321132
expectedBody: `null`,
11331133
},
11341134
{
1135-
code: statusAPIError,
1135+
code: http.StatusUnprocessableEntity,
11361136
response: &apiResponse{
11371137
Status: "error",
11381138
Data: json.RawMessage(`"test"`),
@@ -1177,15 +1177,15 @@ func TestAPIClientDo(t *testing.T) {
11771177
},
11781178
},
11791179
{
1180-
code: statusAPIError,
1180+
code: http.StatusUnprocessableEntity,
11811181
response: "bad json",
11821182
expectedErr: &Error{
11831183
Type: ErrBadResponse,
11841184
Msg: "readObjectStart: expect { or n, but found b, error found in #1 byte of ...|bad json|..., bigger context ...|bad json|...",
11851185
},
11861186
},
11871187
{
1188-
code: statusAPIError,
1188+
code: http.StatusUnprocessableEntity,
11891189
response: &apiResponse{
11901190
Status: "success",
11911191
Data: json.RawMessage(`"test"`),
@@ -1196,7 +1196,7 @@ func TestAPIClientDo(t *testing.T) {
11961196
},
11971197
},
11981198
{
1199-
code: statusAPIError,
1199+
code: http.StatusUnprocessableEntity,
12001200
response: &apiResponse{
12011201
Status: "success",
12021202
Data: json.RawMessage(`"test"`),

0 commit comments

Comments
 (0)