1818
1919from findmy import util
2020from findmy .accessory import RollingKeyPairSource
21+ from findmy .errors import EmptyResponseError
2122from findmy .keys import HasHashedPublicKey , KeyPair , KeyPairMapping , KeyPairType
2223
2324if TYPE_CHECKING :
@@ -417,7 +418,7 @@ async def fetch_location_history(
417418
418419 return reports
419420
420- async def _fetch_accessory_reports (
421+ async def _fetch_accessory_reports ( # noqa: C901
421422 self ,
422423 accessory : RollingKeyPairSource ,
423424 only_latest : bool = False ,
@@ -480,7 +481,10 @@ async def _fetch() -> set[LocationReport]:
480481 len (cur_keys_primary | new_keys_primary ) > 290
481482 or len (cur_keys_secondary | new_keys_secondary ) > 290
482483 ):
483- ret |= await _fetch ()
484+ try :
485+ ret |= await _fetch ()
486+ except EmptyResponseError :
487+ return []
484488
485489 # if we only want the latest report, we can stop here
486490 # since we are iterating backwards in time
@@ -498,7 +502,10 @@ async def _fetch() -> set[LocationReport]:
498502
499503 if cur_keys_primary or cur_keys_secondary :
500504 # fetch remaining keys
501- ret |= await _fetch ()
505+ try :
506+ ret |= await _fetch ()
507+ except EmptyResponseError :
508+ return []
502509
503510 return sorted (ret )
504511
@@ -510,7 +517,10 @@ async def _fetch_key_reports(
510517
511518 # fetch all as primary keys
512519 ids = [([key .hashed_adv_key_b64 ], []) for key in keys ]
513- encrypted_reports : list [LocationReport ] = await self ._account .fetch_raw_reports (ids )
520+ try :
521+ encrypted_reports : list [LocationReport ] = await self ._account .fetch_raw_reports (ids )
522+ except EmptyResponseError :
523+ encrypted_reports = []
514524
515525 id_to_key : dict [bytes , HasHashedPublicKey ] = {key .hashed_adv_key_bytes : key for key in keys }
516526 reports : dict [HasHashedPublicKey , list [LocationReport ]] = {key : [] for key in keys }
0 commit comments