This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle errors returned by Somfy (#147)
- Loading branch information
Showing
12 changed files
with
187 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from typing import Any, Dict | ||
|
||
|
||
class ServerException(Exception): | ||
def __init__(self, response: Dict[str, Any]) -> None: | ||
self.error_code = response["fault"]["detail"]["errorcode"] | ||
self.fault_string = response["fault"]["faultstring"] | ||
super().__init__() | ||
|
||
def __str__(self) -> str: | ||
return f"error_code: {self.error_code}, fault_string: {self.fault_string}" | ||
|
||
|
||
class InvalidAccessTokenException(ServerException): | ||
pass | ||
|
||
|
||
class QuotaViolationException(ServerException): | ||
pass | ||
|
||
|
||
class AccessTokenException(ServerException): | ||
pass | ||
|
||
|
||
class ClientException(Exception): | ||
def __init__(self, response: Dict[str, Any]) -> None: | ||
self.data = response["data"] | ||
self.message = response["message"] | ||
super().__init__() | ||
|
||
def __str__(self) -> str: | ||
return f"message: {self.message}, data: {self.data}" | ||
|
||
|
||
class ValidateException(ClientException): | ||
pass | ||
|
||
|
||
class DeviceNotFoundException(ClientException): | ||
pass | ||
|
||
|
||
class DefinitionNotFoundException(ClientException): | ||
pass | ||
|
||
|
||
class SiteNotFoundException(ClientException): | ||
pass | ||
|
||
|
||
class SetupNotFoundException(ClientException): | ||
pass | ||
|
||
|
||
SERVER_ERROR = { | ||
"oauth.v2.InvalidAccessToken": InvalidAccessTokenException, | ||
"keymanagement.service.access_token_expired": AccessTokenException, | ||
"policies.ratelimit.QuotaViolation": QuotaViolationException, | ||
} | ||
|
||
CLIENT_ERROR = { | ||
"ValidateError": ValidateException, | ||
"device_not_found": DeviceNotFoundException, | ||
"definition_not_found": DefinitionNotFoundException, | ||
"setup_not_found": SetupNotFoundException, | ||
"site_not_found": SiteNotFoundException, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"fault": { | ||
"faultstring": "Access Token expired", | ||
"detail": { | ||
"errorcode": "keymanagement.service.access_token_expired" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"uid": "46779aebccfd", | ||
"message": "definition_not_found", | ||
"data": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"uid": "8b09d5a25940", | ||
"message": "device_not_found", | ||
"transactionId": "a2753340-c918-11eb-b171-a9ae9fdd7072", | ||
"data": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"fault": { | ||
"faultstring": "Invalid access token", | ||
"detail": { | ||
"errorcode": "oauth.v2.InvalidAccessToken" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"fault": { | ||
"detail": { | ||
"errorcode": "policies.ratelimit.QuotaViolation" | ||
}, | ||
"faultstring": "Rate limit quota violation. Quota limit exceeded." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"uid": "867eaca52921", | ||
"message": "setup_not_found", | ||
"transactionId": "4e296110-c90b-11eb-bbf3-619c6ebbae8b", | ||
"data": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"uid": "fbd3dd6bab14", | ||
"message": "site_not_found", | ||
"transactionId": "30703f00-c919-11eb-b171-a9ae9fdd7072", | ||
"data": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"uid": "dd7bf078a314", | ||
"message": "ValidateError", | ||
"transactionId": "2fb262b0-c918-11eb-bbf3-619c6ebbae8b", | ||
"data": { | ||
"fields": { | ||
"command.name": { | ||
"message": "'name' is required" | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters