File tree Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Original file line number Diff line number Diff line change 1
- # Changes in 1.16
1
+ # Changes in 1.17
2
2
3
3
## Breaking changes
4
4
5
5
## New features
6
6
7
7
## Bug fixes
8
8
9
+ * Fix reporting error based on http responses from the Aura-API with an invalid JSON body. Earlier the client would report JSONDecodeError instead of showing the actual issue.
10
+
9
11
## Improvements
10
12
11
13
## Other changes
Original file line number Diff line number Diff line change @@ -351,8 +351,17 @@ def _check_resp(self, resp: requests.Response) -> None:
351
351
352
352
def _check_status_code (self , resp : requests .Response ) -> None :
353
353
if resp .status_code >= 400 :
354
+ message = ""
355
+ try :
356
+ message = resp .json ()
357
+ except requests .JSONDecodeError :
358
+ try :
359
+ message = resp .text
360
+ except Exception :
361
+ message = f"Not parsable body `{ resp .raw .data !r} `"
362
+
354
363
raise AuraApiError (
355
- f"Request for { resp .url } failed with status code { resp .status_code } - { resp .reason } : { resp . json () } " ,
364
+ f"Request for { resp .url } failed with status code { resp .status_code } - { resp .reason } : ` { message } ` " ,
356
365
status_code = resp .status_code ,
357
366
)
358
367
Original file line number Diff line number Diff line change @@ -948,6 +948,43 @@ def test_list_missing_instance(requests_mock: Mocker) -> None:
948
948
assert api .list_instance ("id0" ) is None
949
949
950
950
951
+ def test_list_instance_unknown_error (requests_mock : Mocker ) -> None :
952
+ api = AuraApi ("" , "" , project_id = "some-tenant" )
953
+
954
+ mock_auth_token (requests_mock )
955
+
956
+ requests_mock .get (
957
+ "https://api.neo4j.io/v1/instances/id0" ,
958
+ status_code = 500 ,
959
+ reason = "Not Found" ,
960
+ text = "my text" ,
961
+ )
962
+
963
+ with pytest .raises (
964
+ AuraApiError ,
965
+ match = "Request for https://api.neo4j.io/v1/instances/id0 failed with status code 500 - Not Found: `my text`'" ,
966
+ ):
967
+ api .list_instance ("id0" )
968
+
969
+
970
+ def test_list_instance_unknown_error_empty_body (requests_mock : Mocker ) -> None :
971
+ api = AuraApi ("" , "" , project_id = "some-tenant" )
972
+
973
+ mock_auth_token (requests_mock )
974
+
975
+ requests_mock .get (
976
+ "https://api.neo4j.io/v1/instances/id0" ,
977
+ status_code = 500 ,
978
+ reason = "Not Found" ,
979
+ )
980
+
981
+ with pytest .raises (
982
+ AuraApiError ,
983
+ match = "Request for https://api.neo4j.io/v1/instances/id0 failed with status code 500 - Not Found: ``" ,
984
+ ):
985
+ api .list_instance ("id0" )
986
+
987
+
951
988
def test_dont_wait_forever (requests_mock : Mocker , caplog : LogCaptureFixture ) -> None :
952
989
mock_auth_token (requests_mock )
953
990
requests_mock .get (
You can’t perform that action at this time.
0 commit comments