@@ -733,12 +733,17 @@ def get_bundles(self, parent=None, uuid=None, page=0, size=20, sort=None):
733733 if sort is not None :
734734 params ['sort' ] = sort
735735 r_json = self .fetch_resource (url , params = params )
736- if r_json is None and getattr (self ._last_err , 'status_code' , None ) == 404 :
737- # the item (or bundle) no longer exists - a deleted item simply has
738- # no bundles, which is a clean empty result, not a crash. any other
739- # failure falls through and still surfaces to the caller.
740- _logger .info (f'No bundles: resource not found (404) [{ url } ]' )
741- return bundles
736+ if r_json is None :
737+ status = getattr (self ._last_err , 'status_code' , None )
738+ if status == 404 :
739+ # a deleted item (or bundle) simply has no bundles, which is a
740+ # clean empty result, not a crash.
741+ _logger .info (f'No bundles: resource not found (404) [{ url } ]' )
742+ return bundles
743+ # any other failure surfaces with its status + url, not as an opaque
744+ # 'NoneType is not subscriptable' further down, so the caller can
745+ # see what failed and retry.
746+ raise RuntimeError (f'Failed to fetch bundles: HTTP { status } [{ url } ]' )
742747 try :
743748 if single_result :
744749 bundles .append (Bundle (r_json ))
@@ -800,13 +805,16 @@ def get_bitstreams(self, uuid=None, bundle=None, page=0, size=20, sort=None):
800805 if sort is not None :
801806 params ['sort' ] = sort
802807 r_json = self .fetch_resource (url , params = params )
803- if r_json is None and getattr (self ._last_err , 'status_code' , None ) == 404 :
804- # the bundle (or item) is gone - no bitstreams, a clean empty result
805- # rather than a crash. Mirrors get_bundles (#16). Any other failure
806- # (a transient 5xx, say) falls through and still surfaces to the
807- # caller so it is retried, not silently recorded as "no bitstreams".
808- _logger .info (f'No bitstreams: resource not found (404) [{ url } ]' )
809- return list ()
808+ if r_json is None :
809+ status = getattr (self ._last_err , 'status_code' , None )
810+ if status == 404 :
811+ # the bundle (or item) is gone - no bitstreams, a clean empty
812+ # result rather than a crash. Mirrors get_bundles.
813+ _logger .info (f'No bitstreams: resource not found (404) [{ url } ]' )
814+ return list ()
815+ # a transient 5xx must NOT masquerade as "no bitstreams"; surface it
816+ # with status + url so the caller can retry, not an opaque TypeError.
817+ raise RuntimeError (f'Failed to fetch bitstreams: HTTP { status } [{ url } ]' )
810818 bitstreams = list ()
811819 if '_embedded' in r_json and 'bitstreams' in r_json ['_embedded' ]:
812820 for bitstream_resource in r_json ['_embedded' ]['bitstreams' ]:
0 commit comments