From 5faa5f87ba2f927c86138a74687512aec2bccfc8 Mon Sep 17 00:00:00 2001 From: Adam Simpson Date: Mon, 19 May 2025 15:23:51 -0400 Subject: [PATCH] ds-querier: return 400 when no code is present (#105633) --- pkg/apis/query/v0alpha1/query.go | 4 ++-- pkg/apis/query/v0alpha1/query_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/apis/query/v0alpha1/query.go b/pkg/apis/query/v0alpha1/query.go index 094e96fcacc..ef40c17ff45 100644 --- a/pkg/apis/query/v0alpha1/query.go +++ b/pkg/apis/query/v0alpha1/query.go @@ -31,7 +31,7 @@ type QueryDataResponse struct { // GetResponseCode return the right status code for the response by checking the responses. func GetResponseCode(rsp *backend.QueryDataResponse) int { if rsp == nil { - return http.StatusTeapot // rsp is nil, so we return a teapot + return http.StatusBadRequest // rsp is nil, so we return a 400 } for _, res := range rsp.Responses { if res.Error != nil && res.Status != 0 { @@ -39,7 +39,7 @@ func GetResponseCode(rsp *backend.QueryDataResponse) int { } if res.Error != nil { - return http.StatusTeapot // Status is nil but we have an error, so we return a teapot + return http.StatusBadRequest // Status is nil but we have an error, so we return a 400 } } return http.StatusOK diff --git a/pkg/apis/query/v0alpha1/query_test.go b/pkg/apis/query/v0alpha1/query_test.go index 164e071ec7c..368ebe8dd9e 100644 --- a/pkg/apis/query/v0alpha1/query_test.go +++ b/pkg/apis/query/v0alpha1/query_test.go @@ -93,8 +93,8 @@ func TestGetResponseCode(t *testing.T) { }, })) }) - t.Run("return 418 if there is an error in the responses but no status code", func(t *testing.T) { - assert.Equal(t, 418, query.GetResponseCode(&backend.QueryDataResponse{ + t.Run("return 400 if there is an error in the responses but no status code", func(t *testing.T) { + assert.Equal(t, 400, query.GetResponseCode(&backend.QueryDataResponse{ Responses: map[string]backend.DataResponse{ "A": { Error: fmt.Errorf("some wild error"), @@ -102,8 +102,8 @@ func TestGetResponseCode(t *testing.T) { }, })) }) - t.Run("return 418 if there is a partial error but no status code", func(t *testing.T) { - assert.Equal(t, 418, query.GetResponseCode(&backend.QueryDataResponse{ + t.Run("return 400 if there is a partial error but no status code", func(t *testing.T) { + assert.Equal(t, 400, query.GetResponseCode(&backend.QueryDataResponse{ Responses: map[string]backend.DataResponse{ "A": { Error: nil,