Skip to content

Commit

Permalink
Add new exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jan 1, 2025
1 parent 0168264 commit 22ab283
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions tesla_fleet_api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ class SubscriptionRequired(TeslaFleetError): # Teslemetry specific
status = 402
key = "subscription_required"

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

message = "Vehicle data subscription is required to make this request."
status = 402
key = "vehicle_subscription_required"

class InsufficientCredits(TeslaFleetError):
"""Account has insufficient credits to make this request."""

message = "Account has insufficient command credits to make this request."
status = 402
key = "insufficient_credits"

class Forbidden(TeslaFleetError):
"""Access to this resource is not authorized, developers should check required Scope."""
Expand Down Expand Up @@ -305,21 +318,6 @@ class UnknownFault(TeslaFleetInformationFault):
message = "Unknown fault on signed command."
code = 1


class NotOnWhitelistFault(TeslaFleetInformationFault):
"""Not on whitelist fault on signed command."""

message = "Not on whitelist fault on signed command."
code = 2


class IVSmallerThanExpectedFault(TeslaFleetInformationFault):
"""IV smaller than expected fault on signed command."""

message = "IV smaller than expected fault on signed command."
code = 3


class InvalidTokenFault(TeslaFleetInformationFault):
"""Invalid token fault on signed command."""

Expand Down Expand Up @@ -693,8 +691,13 @@ async def raise_for_status(resp: aiohttp.ClientResponse) -> None:
# This error does not return a body
raise OAuthExpired()
elif resp.status == 402:
if error == SubscriptionRequired.key:
raise SubscriptionRequired(data)
for exception in [
SubscriptionRequired,
VehicleSubscriptionRequired,
InsufficientCredits,
]:
if error == exception.key:
raise exception(data)
raise PaymentRequired(data)
elif resp.status == 403:
if error == UnsupportedVehicle.key:
Expand Down

0 comments on commit 22ab283

Please sign in to comment.