Skip to content

Commit

Permalink
Await for the response before consuming headers or other status.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Sep 25, 2024
1 parent 3eff8c5 commit 49c3d31
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions opensearchpy/connection/http_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,35 @@ async def perform_request(
raw_data = await response.text()
duration = self.loop.time() - start

# raise warnings if any from the 'Warnings' header.
warning_headers = response.headers.getall("warning", ())
self._raise_warnings(warning_headers)

# raise errors based on http status codes, let the client handle those if needed
if not (200 <= response.status < 300) and response.status not in ignore:
self.log_request_fail(
method,
str(url),
url_path,
orig_body,
duration,
status_code=response.status,
response=raw_data,
)
self._raise_error(response.status, raw_data)

self.log_request_success(
method,
str(url),
url_path,
orig_body,
response.status,
raw_data,
duration,
)

return response.status, response.headers, raw_data

# We want to reraise a cancellation or recursion error.
except reraise_exceptions:
raise
Expand All @@ -236,29 +265,6 @@ async def perform_request(
raise ConnectionTimeout("TIMEOUT", str(e), e)
raise ConnectionError("N/A", str(e), e)

# raise warnings if any from the 'Warnings' header.
warning_headers = response.headers.getall("warning", ())
self._raise_warnings(warning_headers)

# raise errors based on http status codes, let the client handle those if needed
if not (200 <= response.status < 300) and response.status not in ignore:
self.log_request_fail(
method,
str(url),
url_path,
orig_body,
duration,
status_code=response.status,
response=raw_data,
)
self._raise_error(response.status, raw_data)

self.log_request_success(
method, str(url), url_path, orig_body, response.status, raw_data, duration
)

return response.status, response.headers, raw_data

async def close(self) -> Any:
"""
Explicitly closes connection
Expand Down

0 comments on commit 49c3d31

Please sign in to comment.