Skip to content

Commit

Permalink
Add LoginRequired
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed May 19, 2024
1 parent cc45496 commit 63a8bc1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tesla_fleet_api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,22 @@ class OAuthExpired(TeslaFleetError):
key = "token expired (401)"


class LoginRequired(TeslaFleetError):
"""The user has reset their password and a new auth code is required, or the refresh_token has already been used."""

message = "The user has reset their password and a new auth code is required, or the refresh_token has already been used."
status = 401
key = "login_required"


class PaymentRequired(TeslaFleetError):
"""Payment is required in order to use the API (non-free account only)."""

message = "Payment is required in order to use the API (non-free account only)."
status = 402


class SubscriptionRequired(TeslaFleetError):
class SubscriptionRequired(TeslaFleetError): # Teslemetry specific
"""Subscription is required in order to use Teslemetry."""

message = "Subscription is required in order to use Teslemetry."
Expand Down Expand Up @@ -266,7 +274,7 @@ async def raise_for_status(resp: aiohttp.ClientResponse) -> None:
raise InvalidRequest(data)
elif resp.status == 401:
if error:
for exception in [OAuthExpired, MobileAccessDisabled]:
for exception in [OAuthExpired, MobileAccessDisabled, LoginRequired]:
if error == exception.key:
raise exception(data)
raise InvalidToken(data)
Expand Down

0 comments on commit 63a8bc1

Please sign in to comment.