Skip to content

Commit bb25085

Browse files
authored
Refactor exception classes for improved clarity and organization (#1776)
1 parent ac68c3b commit bb25085

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pyoverkiz/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
InvalidEventListenerIdException,
5050
InvalidTokenException,
5151
MaintenanceException,
52+
MissingAPIKeyException,
5253
MissingAuthorizationTokenException,
5354
NexityBadCredentialsException,
5455
NexityServiceException,
@@ -999,6 +1000,10 @@ async def check_response(response: ClientResponse) -> None:
9991000
if message == "Not authenticated":
10001001
raise NotAuthenticatedException(message)
10011002

1003+
# {'errorCode': 'AUTHENTICATION_ERROR', 'error': 'An API key is required to access this setup'}
1004+
if message == "An API key is required to access this setup":
1005+
raise MissingAPIKeyException(message)
1006+
10021007
# {"error":"Missing authorization token.","errorCode":"RESOURCE_ACCESS_DENIED"}
10031008
if message == "Missing authorization token":
10041009
raise MissingAuthorizationTokenException(message)
@@ -1019,6 +1024,10 @@ async def check_response(response: ClientResponse) -> None:
10191024
if message == "No registered event listener":
10201025
raise NoRegisteredEventListenerException(message)
10211026

1027+
# {'errorCode': 'AUTHENTICATION_ERROR', 'error': 'No such user account : xxxxx'}
1028+
if "No such user account" in message:
1029+
raise UnknownUserException(message)
1030+
10221031
# {'errorCode': 'INVALID_API_CALL', 'error': 'No such resource'}
10231032
if message == "No such resource":
10241033
raise NoSuchResourceException(message)

pyoverkiz/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class MaintenanceException(ServiceUnavailableException):
4646
"""Raised when the service is under maintenance."""
4747

4848

49+
class MissingAPIKeyException(BaseOverkizException):
50+
"""Raised when the API key is missing."""
51+
52+
4953
class MissingAuthorizationTokenException(BaseOverkizException):
5054
"""Raised when the authorization token is missing."""
5155

0 commit comments

Comments
 (0)