Skip to content

Commit

Permalink
Check error in BaseClient.Perform (#922)
Browse files Browse the repository at this point in the history
* 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 <laurent.saintfelix@elastic.co>
  • Loading branch information
arp242 and Anaethelion committed Nov 27, 2024
1 parent 0e89bee commit 94248db
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,17 +341,20 @@ 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()
return nil, err
}
}

return res, err
return res, nil
}

// InstrumentationEnabled propagates back to the client the Instrumentation provided by the transport.
Expand Down

0 comments on commit 94248db

Please sign in to comment.