diff --git a/pkg/quickwit/client/client.go b/pkg/quickwit/client/client.go index 8124781..c143293 100644 --- a/pkg/quickwit/client/client.go +++ b/pkg/quickwit/client/client.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "net/http" "net/url" @@ -166,13 +167,6 @@ func (c *baseClientImpl) ExecuteMultisearch(r *MultiSearchRequest) (*MultiSearch c.logger.Debug("Received multisearch response", "code", res.StatusCode, "status", res.Status, "content-length", res.ContentLength) - if res.StatusCode >= 400 { - jsonResponseBody, _ := json.Marshal(res.Body) - jsonQueryParam, _ := json.Marshal(queryParams) - jsonRequestBody, _ := json.Marshal(r.Requests) - c.logger.Error("Error on multisearch: statusCode = " + strconv.Itoa(res.StatusCode) + ", responseBody = " + string(jsonResponseBody) + ", queryParam = " + string(jsonQueryParam) + ", requestBody = " + string(jsonRequestBody)) - } - start := time.Now() c.logger.Debug("Decoding multisearch json response") @@ -188,6 +182,16 @@ func (c *baseClientImpl) ExecuteMultisearch(r *MultiSearchRequest) (*MultiSearch msr.Status = res.StatusCode + if res.StatusCode >= 400 { + jsonResponseBody, _ := json.Marshal(res.Body) + jsonQueryParam, _ := json.Marshal(queryParams) + jsonRequestBody, _ := json.Marshal(r.Requests) + err_msg := "Error on multisearch: statusCode = " + strconv.Itoa(res.StatusCode) + ", responseBody = " + string(jsonResponseBody) + ", queryParam = " + string(jsonQueryParam) + ", requestBody = " + string(jsonRequestBody) + c.logger.Error(err_msg) + + return &msr, errors.New(err_msg) + } + return &msr, nil } diff --git a/pkg/quickwit/error_handling_test.go b/pkg/quickwit/error_handling_test.go index d1964d6..fa2b2cf 100644 --- a/pkg/quickwit/error_handling_test.go +++ b/pkg/quickwit/error_handling_test.go @@ -44,11 +44,8 @@ func TestErrorAvgMissingField(t *testing.T) { LogMessageField: "line", LogLevelField: "lvl", } - result, err := queryDataTestWithResponseCode(query, 400, response, configuredFields) - require.NoError(t, err) - - // FIXME: we should return the received error message - require.Len(t, result.response.Responses, 0) + _, err := queryDataTestWithResponseCode(query, 400, response, configuredFields) + require.Error(t, err) } func TestErrorAvgMissingFieldNoDetailedErrors(t *testing.T) { @@ -78,11 +75,8 @@ func TestErrorAvgMissingFieldNoDetailedErrors(t *testing.T) { LogMessageField: "line", LogLevelField: "lvl", } - result, err := queryDataTestWithResponseCode(query, 400, response, configuredFields) - require.NoError(t, err) - - // FIXME: we should return the received error message - require.Len(t, result.response.Responses, 0) + _, err := queryDataTestWithResponseCode(query, 400, response, configuredFields) + require.Error(t, err) } func TestErrorTooManyDateHistogramBuckets(t *testing.T) {