From 4607b7d60ea6228cbf2d5ff4a6a6618fb95f99b9 Mon Sep 17 00:00:00 2001 From: Idriss Neumann Date: Fri, 24 Nov 2023 17:48:54 +0100 Subject: [PATCH] Issue #28: move throw error in order to quit fast --- pkg/quickwit/client/client.go | 20 +++++++++----------- src/datasource.ts | 5 ++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pkg/quickwit/client/client.go b/pkg/quickwit/client/client.go index c143293..a133019 100644 --- a/pkg/quickwit/client/client.go +++ b/pkg/quickwit/client/client.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/json" - "errors" "fmt" "net/http" "net/url" @@ -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() @@ -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 } diff --git a/src/datasource.ts b/src/datasource.ts index 36af503..36cd0a2 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -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 }); @@ -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; })