From 5d7f845df81e8cc71692573dab058788befa3619 Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Mon, 30 Mar 2026 22:14:48 +0200 Subject: [PATCH 1/2] Add ApplicationNotAllowedException and update related tests and JSON fixture --- pyoverkiz/client.py | 5 +++++ pyoverkiz/exceptions.py | 14 +++++++++++--- .../exceptions/cloud/resource-access-denied.json | 4 ++++ tests/test_client.py | 5 +++++ 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/exceptions/cloud/resource-access-denied.json diff --git a/pyoverkiz/client.py b/pyoverkiz/client.py index 772751dd..52171baa 100644 --- a/pyoverkiz/client.py +++ b/pyoverkiz/client.py @@ -61,6 +61,7 @@ NoSuchResourceException, NotAuthenticatedException, NotSuchTokenException, + ApplicationNotAllowedException, OverkizException, ServiceUnavailableException, SessionAndBearerInSameRequestException, @@ -971,6 +972,10 @@ async def check_response(response: ClientResponse) -> None: if "Access denied to gateway" in message: raise AccessDeniedToGatewayException(message) + # {"errorCode": "RESOURCE_ACCESS_DENIED", "error": "Your setup cannot be accessed through this application"} + if message == "Your setup cannot be accessed through this application": + raise ApplicationNotAllowedException(message) + # Undefined Overkiz exception raise OverkizException(result) diff --git a/pyoverkiz/exceptions.py b/pyoverkiz/exceptions.py index 17feca6a..bc380d49 100644 --- a/pyoverkiz/exceptions.py +++ b/pyoverkiz/exceptions.py @@ -29,7 +29,11 @@ class NoSuchResourceException(BaseOverkizException): """Raised when an invalid API call is made.""" -class NotAuthenticatedException(BaseOverkizException): +class ResourceAccessDeniedException(BaseOverkizException): + """Raised when the API returns a RESOURCE_ACCESS_DENIED error.""" + + +class NotAuthenticatedException(ResourceAccessDeniedException): """Raised when the user is not authenticated.""" @@ -61,7 +65,7 @@ class MissingAPIKeyException(BaseOverkizException): """Raised when the API key is missing.""" -class MissingAuthorizationTokenException(BaseOverkizException): +class MissingAuthorizationTokenException(ResourceAccessDeniedException): """Raised when the authorization token is missing.""" @@ -97,10 +101,14 @@ class UnknownObjectException(BaseOverkizException): """Raised when an unknown object is provided.""" -class AccessDeniedToGatewayException(BaseOverkizException): +class AccessDeniedToGatewayException(ResourceAccessDeniedException): """Raised when access is denied to the gateway. This often happens when the user is not the owner of the gateway.""" +class ApplicationNotAllowedException(ResourceAccessDeniedException): + """Raised when the setup cannot be accessed through the application.""" + + # Nexity class NexityBadCredentialsException(BadCredentialsException): """Raised when invalid credentials are provided to Nexity authentication API.""" diff --git a/tests/fixtures/exceptions/cloud/resource-access-denied.json b/tests/fixtures/exceptions/cloud/resource-access-denied.json new file mode 100644 index 00000000..355cd5a9 --- /dev/null +++ b/tests/fixtures/exceptions/cloud/resource-access-denied.json @@ -0,0 +1,4 @@ +{ + "errorCode": "RESOURCE_ACCESS_DENIED", + "error": "Your setup cannot be accessed through this application" +} diff --git a/tests/test_client.py b/tests/test_client.py index bd70a0bb..2efcd91d 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -327,6 +327,11 @@ async def test_get_diagnostic_data(self, client: OverkizClient, fixture_name: st exceptions.AccessDeniedToGatewayException, 400, ), + ( + "cloud/resource-access-denied.json", + exceptions.ApplicationNotAllowedException, + 400, + ), ( "cloud/bad-credentials.json", exceptions.BadCredentialsException, From 5114b6a5fa4ad1741736756f424b657267c91e26 Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Mon, 30 Mar 2026 20:24:10 +0000 Subject: [PATCH 2/2] Add ApplicationNotAllowedException and corresponding JSON fixture --- pyoverkiz/client.py | 2 +- ...resource-access-denied.json => application-not-allowed.json} | 0 tests/test_client.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename tests/fixtures/exceptions/cloud/{resource-access-denied.json => application-not-allowed.json} (100%) diff --git a/pyoverkiz/client.py b/pyoverkiz/client.py index 52171baa..5d409f14 100644 --- a/pyoverkiz/client.py +++ b/pyoverkiz/client.py @@ -44,6 +44,7 @@ from pyoverkiz.exceptions import ( AccessDeniedToGatewayException, ActionGroupSetupNotFoundException, + ApplicationNotAllowedException, BadCredentialsException, CozyTouchBadCredentialsException, CozyTouchServiceException, @@ -61,7 +62,6 @@ NoSuchResourceException, NotAuthenticatedException, NotSuchTokenException, - ApplicationNotAllowedException, OverkizException, ServiceUnavailableException, SessionAndBearerInSameRequestException, diff --git a/tests/fixtures/exceptions/cloud/resource-access-denied.json b/tests/fixtures/exceptions/cloud/application-not-allowed.json similarity index 100% rename from tests/fixtures/exceptions/cloud/resource-access-denied.json rename to tests/fixtures/exceptions/cloud/application-not-allowed.json diff --git a/tests/test_client.py b/tests/test_client.py index 2efcd91d..e1cbe60d 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -328,7 +328,7 @@ async def test_get_diagnostic_data(self, client: OverkizClient, fixture_name: st 400, ), ( - "cloud/resource-access-denied.json", + "cloud/application-not-allowed.json", exceptions.ApplicationNotAllowedException, 400, ),