Skip to content

Commit 563e1d7

Browse files
Anaethelionarp242
andauthored
Check error in BaseClient.Perform (#922) (#923)
* 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: Martin Tournoij <[email protected]>
1 parent 0e89bee commit 563e1d7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

elasticsearch.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,20 @@ func (c *BaseClient) Perform(req *http.Request) (*http.Response, error) {
341341

342342
// Retrieve the original request.
343343
res, err := c.Transport.Perform(req)
344+
if err != nil {
345+
return nil, err
346+
}
344347

345348
// ResponseCheck, we run the header check on the first answer from ES.
346-
if err == nil && (res.StatusCode >= 200 && res.StatusCode < 300) {
349+
if res.StatusCode >= 200 && res.StatusCode < 300 {
347350
checkHeader := func() error { return genuineCheckHeader(res.Header) }
348351
if err := c.doProductCheck(checkHeader); err != nil {
349352
res.Body.Close()
350353
return nil, err
351354
}
352355
}
353356

354-
return res, err
357+
return res, nil
355358
}
356359

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

0 commit comments

Comments
 (0)