diff --git a/pyoverkiz/client.py b/pyoverkiz/client.py index 772751dd..5d409f14 100644 --- a/pyoverkiz/client.py +++ b/pyoverkiz/client.py @@ -44,6 +44,7 @@ from pyoverkiz.exceptions import ( AccessDeniedToGatewayException, ActionGroupSetupNotFoundException, + ApplicationNotAllowedException, BadCredentialsException, CozyTouchBadCredentialsException, CozyTouchServiceException, @@ -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/application-not-allowed.json b/tests/fixtures/exceptions/cloud/application-not-allowed.json new file mode 100644 index 00000000..355cd5a9 --- /dev/null +++ b/tests/fixtures/exceptions/cloud/application-not-allowed.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..e1cbe60d 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/application-not-allowed.json", + exceptions.ApplicationNotAllowedException, + 400, + ), ( "cloud/bad-credentials.json", exceptions.BadCredentialsException,