Skip to content

Commit c4373b8

Browse files
committed
add extended error handling to get_item_mapped_collections function
1 parent e002ce5 commit c4373b8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

dspace_rest_client/client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ def get_item_mapped_collections(self, item):
15531553
"""
15541554
Get the mapped collections of a given item
15551555
@param item: Item object
1556-
@return: Mapped Collection object
1556+
@return: List of mapped collections or None if an error occurs
15571557
"""
15581558
if not isinstance(item, Item):
15591559
logging.error("Need a valid item")
@@ -1564,8 +1564,21 @@ def get_item_mapped_collections(self, item):
15641564
response = self.api_get(url)
15651565
if response.status_code == 200:
15661566
return parse_json(response)
1567+
elif response.status_code == 401:
1568+
logging.error(f"Unauthorized access for item {item.uuid}")
1569+
elif response.status_code == 403:
1570+
logging.error(f"Forbidden access for item {item.uuid}")
1571+
elif response.status_code == 405:
1572+
logging.error(f"Method not allowed for item {item.uuid}")
1573+
elif response.status_code == 422:
1574+
logging.error(
1575+
f"Unprocessable entity for item {item.uuid}: Collection issues"
1576+
)
15671577
else:
1568-
return None
1578+
logging.error(
1579+
f"Unexpected response for item {item.uuid}: {response.status_code}"
1580+
)
1581+
return None
15691582
except Exception as e:
15701583
logging.error(
15711584
f"Error retrieving mapped collections for item {item.uuid}: {e}"

0 commit comments

Comments
 (0)