diff --git a/storage3/_async/file_api.py b/storage3/_async/file_api.py index 3a947eb6..afba98ff 100644 --- a/storage3/_async/file_api.py +++ b/storage3/_async/file_api.py @@ -39,15 +39,17 @@ async def _request( files: Optional[Any] = None, **kwargs: Any, ) -> Response: - response = await self._client.request( - method, url, headers=headers or {}, json=json, files=files, **kwargs - ) try: + response = await self._client.request( + method, url, headers=headers or {}, json=json, files=files, **kwargs + ) response.raise_for_status() except HTTPError: - raise StorageException( - {**response.json(), "statusCode": response.status_code} - ) + try: + resp = response.json() + raise StorageException({**resp, "statusCode": response.status_code}) + except JSONDecodeError: + raise StorageException({"statusCode": response.status_code}) return response diff --git a/storage3/_sync/file_api.py b/storage3/_sync/file_api.py index 18aa7e0f..cc251738 100644 --- a/storage3/_sync/file_api.py +++ b/storage3/_sync/file_api.py @@ -39,15 +39,17 @@ def _request( files: Optional[Any] = None, **kwargs: Any, ) -> Response: - response = self._client.request( - method, url, headers=headers or {}, json=json, files=files, **kwargs - ) try: + response = self._client.request( + method, url, headers=headers or {}, json=json, files=files, **kwargs + ) response.raise_for_status() except HTTPError: - raise StorageException( - {**response.json(), "statusCode": response.status_code} - ) + try: + resp = response.json() + raise StorageException({**resp, "statusCode": response.status_code}) + except JSONDecodeError: + raise StorageException({"statusCode": response.status_code}) return response