Check nil before logging "Failed to close response body..." (#11011)

This commit is contained in:
terencechain
2022-07-08 09:55:12 -07:00
committed by GitHub
parent 80d0a82f9b
commit e80806d455

View File

@@ -165,7 +165,9 @@ func (c *Client) do(ctx context.Context, method string, path string, body io.Rea
}
defer func() {
closeErr := r.Body.Close()
log.WithError(closeErr).Error("Failed to close response body")
if closeErr != nil {
log.WithError(closeErr).Error("Failed to close response body")
}
}()
if r.StatusCode != http.StatusOK {
err = non200Err(r)