Skip to content

Commit 685502b

Browse files
Prefer response body text for non-JSON HTTP errors
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 681f6ff commit 685502b

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

hyperbrowser/transport/async_transport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def _handle_response(self, response: httpx.Response) -> APIResponse:
5252
error_data = response.json()
5353
message = error_data.get("message") or error_data.get("error") or str(e)
5454
except Exception:
55-
message = str(e)
55+
message = response.text or str(e)
5656
raise HyperbrowserError(
5757
message,
5858
status_code=response.status_code,

hyperbrowser/transport/sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _handle_response(self, response: httpx.Response) -> APIResponse:
4040
error_data = response.json()
4141
message = error_data.get("message") or error_data.get("error") or str(e)
4242
except Exception:
43-
message = str(e)
43+
message = response.text or str(e)
4444
raise HyperbrowserError(
4545
message,
4646
status_code=response.status_code,

tests/test_transport_response_handling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_sync_handle_response_with_error_and_non_json_body_raises_hyperbrowser_e
4747
try:
4848
response = _build_response(500, "server exploded")
4949

50-
with pytest.raises(HyperbrowserError):
50+
with pytest.raises(HyperbrowserError, match="server exploded"):
5151
transport._handle_response(response)
5252
finally:
5353
transport.close()
@@ -59,7 +59,7 @@ async def run() -> None:
5959
try:
6060
response = _build_response(500, "server exploded")
6161

62-
with pytest.raises(HyperbrowserError):
62+
with pytest.raises(HyperbrowserError, match="server exploded"):
6363
await transport._handle_response(response)
6464
finally:
6565
await transport.close()

0 commit comments

Comments
 (0)