Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/172.fixed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error responses whose JSON ``error`` value is not a string no longer raise :class:`TypeError` instead of ``httpx2.HTTPStatusError``.
2 changes: 1 addition & 1 deletion src/spacetrack/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ def _raise_for_status(response):

try:
json = response.json()
if isinstance(json, Mapping):
if isinstance(json, Mapping) and isinstance(json["error"], str):
spacetrack_error_msg = json["error"]
except (ValueError, KeyError, httpx2.ResponseNotRead):
pass
Expand Down
15 changes: 15 additions & 0 deletions tests/test_spacetrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,21 @@ def test_raise_for_status(httpx2_mock):
assert "Space-Track" not in str(exc.value)


def test_raise_for_status_non_string_error(httpx2_mock):
httpx2_mock.add_response(
method="GET",
url="http://example.com/1",
status_code=400,
json={"error": 12345},
)

response = httpx2.get("http://example.com/1")

with pytest.raises(httpx2.HTTPStatusError) as exc:
_raise_for_status(response)
assert '{"error":12345}' in str(exc.value)


def test_repr(httpx2_mock):
with SpaceTrackClient("hello@example.com", "mypassword") as client:
assert repr(client) == "SpaceTrackClient<identity='hello@example.com'>"
Expand Down