Skip to content

Commit e65b161

Browse files
committed
Fix 429/auth error display in demo.py and example.py - catch GarminConnectTooManyRequestsError with clean user-facing messages, print detailed auth error causes
1 parent c4d7f93 commit e65b161

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

demo.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4146,6 +4146,10 @@ def init_api(email: str | None = None, password: str | None = None) -> Garmin |
41464146
print("Successfully logged in using stored tokens!")
41474147
return garmin
41484148

4149+
except GarminConnectTooManyRequestsError as err:
4150+
print(f"\n{err}")
4151+
sys.exit(1)
4152+
41494153
except (
41504154
FileNotFoundError,
41514155
GarthHTTPError,
@@ -4207,8 +4211,12 @@ def init_api(email: str | None = None, password: str | None = None) -> Garmin |
42074211

42084212
return garmin
42094213

4210-
except GarminConnectAuthenticationError:
4211-
print("❌ Authentication failed:")
4214+
except GarminConnectTooManyRequestsError as err:
4215+
print(f"\n{err}")
4216+
sys.exit(1)
4217+
4218+
except GarminConnectAuthenticationError as err:
4219+
print(f"\n{err}")
42124220
print("💡 Please check your username and password and try again")
42134221
# Clear the provided credentials to force re-entry
42144222
email = None

example.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ def init_api() -> Garmin | None:
155155
garmin.login(str(tokenstore_path))
156156
return garmin
157157

158+
except GarminConnectTooManyRequestsError as err:
159+
print(f"\n{err}")
160+
sys.exit(1)
161+
158162
except (
159163
FileNotFoundError,
160164
GarthHTTPError,
@@ -198,6 +202,10 @@ def init_api() -> Garmin | None:
198202
garmin.garth.dump(str(tokenstore_path))
199203
return garmin
200204

205+
except GarminConnectTooManyRequestsError as err:
206+
print(f"\n{err}")
207+
sys.exit(1)
208+
201209
except GarminConnectAuthenticationError:
202210
# Continue the loop to retry
203211
continue

0 commit comments

Comments
 (0)