File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -102,9 +102,13 @@ def request_ws(
102102 if response_as_json :
103103 try :
104104 return request_result .json ()
105- except requests .exceptions .JSONDecodeError as e :
106- error_msg = f"Invalid JSON response: { e } . Response content: { request_result .text } "
107- raise requests .exceptions .JSONDecodeError (error_msg , request_result .text , e .pos ) from e
105+ except requests .exceptions .JSONDecodeError as json_error :
106+ error_msg = "Invalid JSON response: {0}. Response content: {1}" .format (
107+ json_error , request_result .text
108+ )
109+ raise requests .exceptions .JSONDecodeError (
110+ error_msg , request_result .text , 0
111+ ) from json_error
108112 return request_result
109113
110114 def get_braincube_infos (self ) -> Dict [str , Any ]:
Original file line number Diff line number Diff line change @@ -62,20 +62,21 @@ def test_request_ws_succes_no_json(mock_client):
6262 )
6363 assert type (result ) == requests .models .Response
6464
65+
6566@responses .activate
6667def test_request_ws_json_decode_error_with_content (mock_client ):
6768 """Test whether request_ws includes response content in JSON decode error messages."""
6869 # Mock a response that returns non-JSON content
6970 responses .add (
70- responses .GET ,
71- LOAD_URL ,
71+ responses .GET ,
72+ LOAD_URL ,
7273 body = "<html><body>Response content not JSON</body></html>" ,
73- status = 200
74+ status = 200 ,
7475 )
75-
76+
7677 with pytest .raises (requests .exceptions .JSONDecodeError ) as excinfo :
7778 mock_client .request_ws ("path" , response_as_json = True )
78-
79+
7980 # Check that the error message contains the response content
8081 error_message = str (excinfo .value )
8182 assert "Invalid JSON response" in error_message
You can’t perform that action at this time.
0 commit comments