Skip to content

Commit

Permalink
Raise InvalidTokenException on invalid token (#1874)
Browse files Browse the repository at this point in the history
Invalid checksum raises now a more specialized `InvalidTokenException`.
This will allow downstreams to request the user to check the token.
  • Loading branch information
rytilahti committed Dec 5, 2023
1 parent dac61d4 commit 5241bcc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions miio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from miio.devicestatus import DeviceStatus
from miio.exceptions import (
DeviceError,
InvalidTokenException,
DeviceException,
UnsupportedFeatureException,
DeviceInfoUnavailableException,
Expand Down
4 changes: 4 additions & 0 deletions miio/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ class DeviceException(Exception):
"""Exception wrapping any communication errors with the device."""


class InvalidTokenException(DeviceException):
"""Exception raised when invalid token is detected."""


class PayloadDecodeException(DeviceException):
"""Exception for failures in payload decoding.
Expand Down
9 changes: 7 additions & 2 deletions miio/miioprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

import construct

from .exceptions import DeviceError, DeviceException, RecoverableError
from .exceptions import (
DeviceError,
DeviceException,
InvalidTokenException,
RecoverableError,
)
from .protocol import Message

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -219,7 +224,7 @@ def send(
except KeyError:
return payload
except construct.core.ChecksumError as ex:
raise DeviceException(
raise InvalidTokenException(
"Got checksum error which indicates use "
"of an invalid token. "
"Please check your token!"
Expand Down

0 comments on commit 5241bcc

Please sign in to comment.