Skip to content

Commit

Permalink
Issue #28: throw the errors coming from quickwit
Browse files Browse the repository at this point in the history
  • Loading branch information
idrissneumann committed Dec 14, 2023
1 parent 8e2e09d commit 06d6916
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
18 changes: 11 additions & 7 deletions pkg/quickwit/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -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")

Expand All @@ -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
}

Expand Down
14 changes: 4 additions & 10 deletions pkg/quickwit/error_handling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 06d6916

Please sign in to comment.