Skip to content

Commit

Permalink
Handle empty responses
Browse files Browse the repository at this point in the history
  • Loading branch information
bendikrb committed Nov 6, 2023
1 parent 6462ccd commit 063129d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions kassalappy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ def path_to_model(req_path: str) -> type[KassalappResource] | None:
async def extract_response_data(
response: aiohttp.ClientResponse,
map_to_model: bool = False,
) -> dict[any, any] | KassalappResource | list[KassalappResource]:
) -> dict[any, any] | KassalappResource | list[KassalappResource] | None:
"""Extract the response as JSON and map to appropriate dataclass."""
if response.ok and response.content_length == 0:
_LOGGER.debug("Got an empty OK-like response, returning.")
return

if response.content_type != "application/json":
raise FatalHttpException(
response.status,
Expand All @@ -48,7 +52,6 @@ async def extract_response_data(
)

result = await response.json()

if response.ok:
data = result.get("data")
if map_to_model:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "kassalappy"
version = "0.5.0"
version = "0.6.0"
description = ""
authors = ["Bendik R. Brenne <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 063129d

Please sign in to comment.