Skip to content

Add exception for un-reachable host #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sagemcom_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Dict, List, Optional, Type
import urllib.parse

from aiohttp import ClientSession, ClientTimeout
from aiohttp import ClientConnectionError, ClientSession, ClientTimeout
from aiohttp.connector import TCPConnector
import humps

Expand All @@ -33,6 +33,7 @@
AccessRestrictionException,
AuthenticationException,
BadRequestException,
LoginConnectionException,
LoginTimeoutException,
MaximumSessionCountException,
NonWritableParameterException,
Expand Down Expand Up @@ -272,6 +273,10 @@ async def login(self):
raise LoginTimeoutException(
"Request timed-out. This is mainly due to using the wrong encryption method."
) from exception
except ClientConnectionError as exception:
raise LoginConnectionException(
"Unable to connect to the device. Please check the host address."
) from exception

data = self.__get_response(response)

Expand Down
6 changes: 6 additions & 0 deletions sagemcom_api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class LoginTimeoutException(Exception):
pass


class LoginConnectionException(Exception):
"""Raised when a connection error is encountered during login."""

pass


class NonWritableParameterException(Exception):
"""Raised when provided parameter is not writable."""

Expand Down