Skip to content

Commit

Permalink
Fix AttributeError in DigitalLandJSONResponse (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
feba-rajan authored Aug 5, 2024
1 parent d45be6d commit 6b4bf07
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions application/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from starlette.responses import Response

logger = logging.getLogger(__name__)


def create_dict(keys_list, values_list):
zip_iterator = zip(keys_list, values_list)
Expand Down Expand Up @@ -82,14 +84,21 @@ class DigitalLandJSONResponse(Response):
media_type = "application/json"

def render(self, content: typing.Any) -> bytes:
return json.dumps(
content,
ensure_ascii=False,
allow_nan=False,
indent=None,
separators=(",", ":"),
cls=NoneToEmptyStringEncoder,
).encode("utf-8")
try:
if isinstance(content, dict):
return json.dumps(
content,
ensure_ascii=False,
allow_nan=False,
indent=None,
separators=(",", ":"),
cls=NoneToEmptyStringEncoder,
).encode("utf-8")
else:
raise TypeError("Content must be a dictionary")
except Exception as e:
logger.error(f"Error rendering content: {e}")
raise


def make_links(scheme, netloc, path, query, data):
Expand Down

0 comments on commit 6b4bf07

Please sign in to comment.