Skip to content

Commit

Permalink
fix: better handling of text responses (#118)
Browse files Browse the repository at this point in the history
## changes

small fix to handle text responses
  • Loading branch information
sg-s authored Nov 22, 2024
1 parent 9825193 commit 9f1964c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/data_hub/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,21 @@ def dynamic_function(
)

if not isinstance(response, dict):
response = response.json()
if "json" in response.headers["content-type"]:
response = response.json()
elif "text" in response.headers["content-type"]:
response = response.text()
else:
raise DeepOriginException(
f"Uncertain response type: {response.headers}"
)

if "data" in response.keys():
if isinstance(response, dict) and "data" in response.keys():
response = response["data"]
if isinstance(response, list):
response = [Box(item) for item in response]
else:
response = Box(response)
else:

if isinstance(response, list):
response = [Box(item) for item in response]
elif isinstance(response, dict):
response = Box(response)

if _stash:
Expand Down

0 comments on commit 9f1964c

Please sign in to comment.