Skip to content

Commit 0ed1c45

Browse files
Add exception for un-reachable host
1 parent a40a618 commit 0ed1c45

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

sagemcom_api/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing import Dict, List, Optional, Type
1111
import urllib.parse
1212

13-
from aiohttp import ClientSession, ClientTimeout
13+
from aiohttp import ClientConnectionError, ClientSession, ClientTimeout
1414
from aiohttp.connector import TCPConnector
1515
import humps
1616

@@ -33,6 +33,7 @@
3333
AccessRestrictionException,
3434
AuthenticationException,
3535
BadRequestException,
36+
LoginConnectionException,
3637
LoginTimeoutException,
3738
MaximumSessionCountException,
3839
NonWritableParameterException,
@@ -272,6 +273,10 @@ async def login(self):
272273
raise LoginTimeoutException(
273274
"Request timed-out. This is mainly due to using the wrong encryption method."
274275
) from exception
276+
except ClientConnectionError as exception:
277+
raise LoginConnectionException(
278+
"Unable to connect to the device. Please check the host address."
279+
) from exception
275280

276281
data = self.__get_response(response)
277282

sagemcom_api/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ class LoginTimeoutException(Exception):
2020
pass
2121

2222

23+
class LoginConnectionException(Exception):
24+
"""Raised when a connection error is encountered during login."""
25+
26+
pass
27+
28+
2329
class NonWritableParameterException(Exception):
2430
"""Raised when provided parameter is not writable."""
2531

0 commit comments

Comments
 (0)