ds-querier: handle execute errors better (#105496)
* ds-querier: handle execute errors better * fix: change how GetResponseCode works to return 418 if rsp is nil 418 is a bit of an easter egg which in this case works since we don't have an rsp but we do know something went wrong, so a 200 won't work. Also changed this to return the code in the frame, not sure why we weren't. * tests: fix GetResponseCode tests * log no rsp case * bring back og error log
This commit is contained in:
@@ -31,11 +31,15 @@ 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.StatusBadRequest
|
||||
return http.StatusTeapot // rsp is nil, so we return a teapot
|
||||
}
|
||||
for _, res := range rsp.Responses {
|
||||
if res.Error != nil && res.Status != 0 {
|
||||
return int(res.Status)
|
||||
}
|
||||
|
||||
if res.Error != nil {
|
||||
return http.StatusBadRequest
|
||||
return http.StatusTeapot // Status is nil but we have an error, so we return a teapot
|
||||
}
|
||||
}
|
||||
return http.StatusOK
|
||||
|
||||
@@ -93,8 +93,8 @@ func TestGetResponseCode(t *testing.T) {
|
||||
},
|
||||
}))
|
||||
})
|
||||
t.Run("return 400 if there is an error in the responses", func(t *testing.T) {
|
||||
assert.Equal(t, 400, query.GetResponseCode(&backend.QueryDataResponse{
|
||||
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{
|
||||
Responses: map[string]backend.DataResponse{
|
||||
"A": {
|
||||
Error: fmt.Errorf("some wild error"),
|
||||
@@ -102,8 +102,8 @@ func TestGetResponseCode(t *testing.T) {
|
||||
},
|
||||
}))
|
||||
})
|
||||
t.Run("return 400 if there is a partial error", func(t *testing.T) {
|
||||
assert.Equal(t, 400, query.GetResponseCode(&backend.QueryDataResponse{
|
||||
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{
|
||||
Responses: map[string]backend.DataResponse{
|
||||
"A": {
|
||||
Error: nil,
|
||||
|
||||
Reference in New Issue
Block a user