From 6cd666c20b5700d3789e814c6c8fcbe82e9dc5be Mon Sep 17 00:00:00 2001 From: Srinivas Gorur-Shandilya Date: Fri, 22 Nov 2024 15:55:47 -0500 Subject: [PATCH] fix: better handling of text responses --- src/data_hub/_api.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/data_hub/_api.py b/src/data_hub/_api.py index b34cdf1..77ebe0e 100644 --- a/src/data_hub/_api.py +++ b/src/data_hub/_api.py @@ -7,6 +7,7 @@ import inspect import json import sys +from json import JSONDecodeError from pathlib import Path from beartype import beartype @@ -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: