diff --git a/pymammotion/aliyun/cloud_gateway.py b/pymammotion/aliyun/cloud_gateway.py index 17e6096..0b71eef 100644 --- a/pymammotion/aliyun/cloud_gateway.py +++ b/pymammotion/aliyun/cloud_gateway.py @@ -55,6 +55,8 @@ class AuthRefreshException(Exception): class DeviceOfflineException(Exception): """Raise exception when device is offline.""" +class LoginException(Exception): + """Raise exception when library cannot log in.""" class CloudIOTGateway: """Class for interacting with Aliyun Cloud IoT Gateway.""" @@ -303,8 +305,11 @@ async def connect(self): params={"request": json.dumps(_bodyParam, separators=(",", ":"))}, ) as resp: data = await resp.json() - self._connect_response = ConnectResponse.from_dict(data) logger.debug(data) + if resp.status == 200: + self._connect_response = ConnectResponse.from_dict(data) + return self._connect_response + raise LoginException(data) async def login_by_oauth(self, country_code: str, auth_code: str): """Login by OAuth.""" @@ -372,8 +377,10 @@ async def login_by_oauth(self, country_code: str, auth_code: str): ) as resp: data = await resp.json() logger.debug(data) - - self._login_by_oauth_response = LoginByOAuthResponse.from_dict(data) + if resp.status == 200: + self._login_by_oauth_response = LoginByOAuthResponse.from_dict(data) + return self._login_by_oauth_response + raise LoginException(data) def session_by_auth_code(self): """Create a session by auth code.""" diff --git a/pyproject.toml b/pyproject.toml index 86239a0..a18f2d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [project] name = "pymammotion" -version = "0.2.15" +version = "0.2.16" [tool.poetry] name = "pymammotion" -version = "0.2.15" +version = "0.2.16" license = "GNU-3.0" description = "" readme = "README.md" @@ -53,7 +53,7 @@ mypy = "^1.10.0" pre-commit = "^3.7.1" [tool.bumpver] -current_version = "0.2.15" +current_version = "0.2.16" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true