Skip to content

Commit 4ce5db8

Browse files
authored
Merge pull request #5 from alexandrehassan/host_exception
Add exception for un-reachable host
2 parents 40217bb + 0ed1c45 commit 4ce5db8

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,
@@ -275,6 +276,10 @@ async def login(self):
275276
raise LoginTimeoutException(
276277
"Request timed-out. This is mainly due to using the wrong encryption method."
277278
) from exception
279+
except ClientConnectionError as exception:
280+
raise LoginConnectionException(
281+
"Unable to connect to the device. Please check the host address."
282+
) from exception
278283

279284
data = self.__get_response(response)
280285

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)