Skip to content

Commit

Permalink
fix: handle json decode error when there's no json response (e.g. on …
Browse files Browse the repository at this point in the history
…403) (#203)

Co-authored-by: joel <joel@joels-MacBook-Pro.local>
  • Loading branch information
J0 and joel authored Mar 10, 2024
1 parent bcb0af7 commit cce5ad4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions storage3/_async/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 8 additions & 6 deletions storage3/_sync/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cce5ad4

Please sign in to comment.