Skip to content

Commit 90f41db

Browse files
committed
handle potential None values
1 parent b7a8160 commit 90f41db

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

dspace_rest_client/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ def parse_json(response):
5252
"""
5353
response_json = None
5454
try:
55-
response_json = response.json()
55+
if response is not None:
56+
response_json = response.json()
5657
except ValueError as err:
57-
logging.error(
58-
"Error parsing response JSON: %s. Body text: %s", err, response.text
59-
)
58+
if response is not None:
59+
logging.error(
60+
"Error parsing response JSON: %s. Body text: %s", err, response.text
61+
)
62+
else:
63+
logging.error("Error parsing response JSON: %s. Response is None", err)
6064
return response_json
6165

6266

@@ -817,6 +821,12 @@ def get_bitstreams(
817821
if "bitstreams" in bundle.links:
818822
url = bundle.links["bitstreams"]["href"]
819823
else:
824+
if bundle is None:
825+
logging.error("Bundle cannot be None")
826+
return []
827+
if bundle is None:
828+
logging.error("Bundle cannot be None")
829+
return []
820830
url = f"{self.API_ENDPOINT}/core/bundles/{bundle.uuid}/bitstreams"
821831
logging.warning(
822832
"Cannot find bundle bitstream links, will try to construct manually: %s",

0 commit comments

Comments
 (0)