From 01fe1fa2feec7d1d51cb56ea3db8be300b6943f7 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Wed, 27 Nov 2024 12:49:02 +0000 Subject: [PATCH] Check error in BaseClient.Perform (#922) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Check error in BaseClient.Perform The http.Resonse will be nil on errors, so return early. Fixes #913 * revert reordering of imports --------- Co-authored-by: Laurent Saint-FĂ©lix --- elasticsearch.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/elasticsearch.go b/elasticsearch.go index c736ded991..8434bd3f52 100644 --- a/elasticsearch.go +++ b/elasticsearch.go @@ -341,9 +341,12 @@ func (c *BaseClient) Perform(req *http.Request) (*http.Response, error) { // Retrieve the original request. res, err := c.Transport.Perform(req) + if err != nil { + return nil, err + } // ResponseCheck, we run the header check on the first answer from ES. - if err == nil && (res.StatusCode >= 200 && res.StatusCode < 300) { + if res.StatusCode >= 200 && res.StatusCode < 300 { checkHeader := func() error { return genuineCheckHeader(res.Header) } if err := c.doProductCheck(checkHeader); err != nil { res.Body.Close() @@ -351,7 +354,7 @@ func (c *BaseClient) Perform(req *http.Request) (*http.Response, error) { } } - return res, err + return res, nil } // InstrumentationEnabled propagates back to the client the Instrumentation provided by the transport.