File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Error responses whose JSON ``error `` value is not a string no longer raise :class: `TypeError ` instead of ``httpx2.HTTPStatusError ``.
Original file line number Diff line number Diff line change @@ -1226,7 +1226,7 @@ def _raise_for_status(response):
12261226
12271227 try :
12281228 json = response .json ()
1229- if isinstance (json , Mapping ):
1229+ if isinstance (json , Mapping ) and isinstance ( json [ "error" ], str ) :
12301230 spacetrack_error_msg = json ["error" ]
12311231 except (ValueError , KeyError , httpx2 .ResponseNotRead ):
12321232 pass
Original file line number Diff line number Diff line change @@ -724,6 +724,21 @@ def test_raise_for_status(httpx2_mock):
724724 assert "Space-Track" not in str (exc .value )
725725
726726
727+ def test_raise_for_status_non_string_error (httpx2_mock ):
728+ httpx2_mock .add_response (
729+ method = "GET" ,
730+ url = "http://example.com/1" ,
731+ status_code = 400 ,
732+ json = {"error" : 12345 },
733+ )
734+
735+ response = httpx2 .get ("http://example.com/1" )
736+
737+ with pytest .raises (httpx2 .HTTPStatusError ) as exc :
738+ _raise_for_status (response )
739+ assert '{"error":12345}' in str (exc .value )
740+
741+
727742def test_repr (httpx2_mock ):
728743 with SpaceTrackClient ("hello@example.com" , "mypassword" ) as client :
729744 assert repr (client ) == "SpaceTrackClient<identity='hello@example.com'>"
You can’t perform that action at this time.
0 commit comments