Skip to content

Commit f9ca942

Browse files
vidiecanjmclaude
authored
fix(client): return empty bundles on 404 instead of crashing (#16)
get_bundles() subscripted the None that fetch_resource returns on any non-200 response, so an item deleted since the cache was built (404) raised "'NoneType' object is not subscriptable" during a bitstream export - a scary CRITICAL line for what is really just "this item is gone". Record the failing response as _last_err in fetch_resource so callers can tell a gone resource (404) from a transient 5xx, then in get_bundles treat a 404 as a clean empty result. Any other failure still falls through and surfaces to the caller, so it keeps its retry and failure counting. Co-authored-by: jm <jm@maz> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent d3c8673 commit f9ca942

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

dspace_rest_client/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@ def fetch_resource(self, url, params=None):
475475
"""
476476
r = self.api_get(url, params, None)
477477
if r.status_code != 200:
478+
# record the failing response so callers can tell a 404 (the
479+
# resource is gone) from a transient 5xx before we drop the body
480+
self._last_err = r
478481
_logger.error(f'Error encountered fetching resource: {r.text}')
479482
return None
480483
# ValueError / JSON handling moved to static method
@@ -698,6 +701,12 @@ def get_bundles(self, parent=None, uuid=None, page=0, size=20, sort=None):
698701
if sort is not None:
699702
params['sort'] = sort
700703
r_json = self.fetch_resource(url, params=params)
704+
if r_json is None and getattr(self._last_err, 'status_code', None) == 404:
705+
# the item (or bundle) no longer exists - a deleted item simply has
706+
# no bundles, which is a clean empty result, not a crash. any other
707+
# failure falls through and still surfaces to the caller.
708+
_logger.info(f'No bundles: resource not found (404) [{url}]')
709+
return bundles
701710
try:
702711
if single_result:
703712
bundles.append(Bundle(r_json))

0 commit comments

Comments
 (0)