@@ -403,14 +403,16 @@ def login(self, /, tokenstore: str | None = None) -> tuple[str | None, str | Non
403403 raise GarminConnectAuthenticationError (
404404 "Failed to retrieve profile"
405405 ) from e
406- if not prof or "displayName" not in prof :
406+ if not prof or not isinstance ( prof , dict ) or "displayName" not in prof :
407407 raise GarminConnectAuthenticationError ("Invalid profile data found" )
408408 # Use profile data directly since garth.profile is read-only
409409 self .display_name = prof .get ("displayName" )
410410 self .full_name = prof .get ("fullName" )
411411 else :
412- self .display_name = self .garth .profile .get ("displayName" )
413- self .full_name = self .garth .profile .get ("fullName" )
412+ profile = self .garth .profile
413+ if isinstance (profile , dict ):
414+ self .display_name = profile .get ("displayName" )
415+ self .full_name = profile .get ("fullName" )
414416
415417 settings = self .garth .connectapi (self .garmin_connect_user_settings_url )
416418
@@ -419,7 +421,7 @@ def login(self, /, tokenstore: str | None = None) -> tuple[str | None, str | Non
419421 "Failed to retrieve user settings"
420422 )
421423
422- if "userData" not in settings :
424+ if not isinstance ( settings , dict ) or "userData" not in settings :
423425 raise GarminConnectAuthenticationError ("Invalid user settings found" )
424426
425427 self .unit_system = settings ["userData" ].get ("measurementSystem" )
@@ -477,11 +479,13 @@ def resume_login(
477479 result1 , result2 = self .garth .resume_login (client_state , mfa_code )
478480
479481 if self .garth .profile :
480- self .display_name = self .garth .profile ["displayName" ]
481- self .full_name = self .garth .profile ["fullName" ]
482+ profile = self .garth .profile
483+ if isinstance (profile , dict ):
484+ self .display_name = profile .get ("displayName" )
485+ self .full_name = profile .get ("fullName" )
482486
483487 settings = self .garth .connectapi (self .garmin_connect_user_settings_url )
484- if settings and "userData" in settings :
488+ if settings and isinstance ( settings , dict ) and "userData" in settings :
485489 self .unit_system = settings ["userData" ]["measurementSystem" ]
486490
487491 return result1 , result2
0 commit comments