Skip to content

Commit

Permalink
fix: better handling of text responses
Browse files Browse the repository at this point in the history
  • Loading branch information
sg-s committed Nov 22, 2024
1 parent 9825193 commit 6cd666c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/data_hub/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import inspect
import json
import sys
from json import JSONDecodeError
from pathlib import Path

from beartype import beartype
Expand Down Expand Up @@ -183,12 +184,17 @@ def dynamic_function(
)

if not isinstance(response, dict):
response = response.json()
try:
response = response.json()
except JSONDecodeError:
response = dict(data=response.text())

if "data" in response.keys():
response = response["data"]
if isinstance(response, list):
response = [Box(item) for item in response]
elif isinstance(response, str):
return response
else:
response = Box(response)
else:
Expand Down

0 comments on commit 6cd666c

Please sign in to comment.