Skip to content

Commit

Permalink
Issue #28: move throw error in order to quit fast
Browse files Browse the repository at this point in the history
  • Loading branch information
idrissneumann committed Nov 24, 2023
1 parent a7603bf commit 4607b7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
20 changes: 9 additions & 11 deletions pkg/quickwit/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -165,6 +164,15 @@ func (c *baseClientImpl) ExecuteMultisearch(r *MultiSearchRequest) (*MultiSearch
}
}()

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 nil, fmt.Errorf(err_msg)
}

c.logger.Debug("Received multisearch response", "code", res.StatusCode, "status", res.Status, "content-length", res.ContentLength)

start := time.Now()
Expand All @@ -182,16 +190,6 @@ 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
5 changes: 2 additions & 3 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ export class QuickwitDataSource
catchError((err) => {
if (err.status === 404) {
return of({ status: 'error', message: 'Index does not exists.' });
}
else if (err.message) {
} else if (err.message) {
return of({ status: 'error', message: err.message });
} else {
return of({ status: 'error', message: err.status });
Expand Down Expand Up @@ -487,7 +486,7 @@ export class QuickwitDataSource
const error: DataQueryError = {
message: 'Error during context query. Please check JS console logs.',
status: err.status,
statusText: err.statusText,
statusText: err.message,
};
throw error;
})
Expand Down

0 comments on commit 4607b7d

Please sign in to comment.