Skip to content

Commit

Permalink
add non_json_response code and fixup test
Browse files Browse the repository at this point in the history
  • Loading branch information
mjurbanski-reef committed Jan 19, 2024
1 parent 0bca983 commit 431a37b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions b2sdk/b2http.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ def _translate_errors(cls, fcn, post_params=None):
raise PotentialS3EndpointPassedAsRealm(response.content)
error = {
'message': response.content.decode('utf-8', errors='replace'),
'code': 'non_json_response',
}
extra_error_keys = error.keys() - ('code', 'status', 'message')
if extra_error_keys:
Expand Down
5 changes: 2 additions & 3 deletions test/unit/b2http/test_b2http.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ def test_invalid_json(self):
response.content = b'{' * 500
response.url = 'https://example.com'

with self.assertRaises(BadRequest) as error:
with pytest.raises(BadRequest) as exc_info:
B2Http._translate_errors(lambda: response)

content_length = min(len(response.content), len(error.content))
self.assertEqual(response.content[:content_length], error.content[:content_length])
assert str(exc_info.value) == f"{response.content.decode()} (non_json_response)"

def test_potential_s3_endpoint_passed_as_realm(self):
response = MagicMock()
Expand Down

0 comments on commit 431a37b

Please sign in to comment.