Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pyoverkiz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from pyoverkiz.exceptions import (
AccessDeniedToGatewayException,
ActionGroupSetupNotFoundException,
ApplicationNotAllowedException,
BadCredentialsException,
CozyTouchBadCredentialsException,
CozyTouchServiceException,
Expand Down Expand Up @@ -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)

Expand Down
14 changes: 11 additions & 3 deletions pyoverkiz/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""


Expand Down Expand Up @@ -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."""


Expand Down Expand Up @@ -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."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errorCode": "RESOURCE_ACCESS_DENIED",
"error": "Your setup cannot be accessed through this application"
}
5 changes: 5 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading