From 9fda038bbf4d338d8b544c59b24ff3df340e81e5 Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Sat, 10 Aug 2024 00:52:28 +0200 Subject: [PATCH] Add unsupported host exception (#339) --- sagemcom_api/client.py | 5 +++++ sagemcom_api/exceptions.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/sagemcom_api/client.py b/sagemcom_api/client.py index 39b7221..f5ee81a 100644 --- a/sagemcom_api/client.py +++ b/sagemcom_api/client.py @@ -51,6 +51,7 @@ UnauthorizedException, UnknownException, UnknownPathException, + UnsupportedHostException, ) from .models import Device, DeviceInfo, PortMapping @@ -203,6 +204,10 @@ async def __post(self, url, data): result = await response.text() raise BadRequestException(result) + if response.status == 404: + result = await response.text() + raise UnsupportedHostException(result) + if response.status != 200: result = await response.text() raise UnknownException(result) diff --git a/sagemcom_api/exceptions.py b/sagemcom_api/exceptions.py index 4fb2933..b547e34 100644 --- a/sagemcom_api/exceptions.py +++ b/sagemcom_api/exceptions.py @@ -18,6 +18,10 @@ class UnknownException(BaseSagemcomException): """Unknown exception.""" +class UnsupportedHostException(BaseSagemcomException): + """Raised when API is not available on given host.""" + + # Exceptions provided by SagemCom API class AccessRestrictionException(BaseSagemcomException): """Raised when current user has access restrictions."""