Module pyControl4.error_handling
Handles errors recieved from the Control4 API.
Functions
async def checkResponseForError(response_text: str)
-
Expand source code
async def checkResponseForError(response_text: str): """Checks a string response from the Control4 API for error codes. Parameters: `response_text` - JSON or XML response from Control4, as a string. """ if await __checkResponseFormat(response_text) == "JSON": dictionary = json.loads(response_text) elif await __checkResponseFormat(response_text) == "XML": dictionary = xmltodict.parse(response_text) if "C4ErrorResponse" in dictionary: if ( "details" in dictionary["C4ErrorResponse"] and dictionary["C4ErrorResponse"]["details"] in ERROR_DETAILS ): exception = ERROR_DETAILS.get(dictionary["C4ErrorResponse"]["details"]) raise exception(response_text) else: exception = ERROR_CODES.get( str(dictionary["C4ErrorResponse"]["code"]), C4Exception ) raise exception(response_text) elif "code" in dictionary: if "details" in dictionary and dictionary["details"] in ERROR_DETAILS: exception = ERROR_DETAILS.get(dictionary["details"]) raise exception(response_text) else: exception = ERROR_CODES.get(str(dictionary["code"]), C4Exception) raise exception(response_text) elif "error" in dictionary: if "details" in dictionary and dictionary["details"] in DIRECTOR_ERROR_DETAILS: exception = DIRECTOR_ERROR_DETAILS.get(dictionary["details"]) raise exception(response_text) else: exception = DIRECTOR_ERRORS.get(str(dictionary["error"]), C4Exception) raise exception(response_text)
Checks a string response from the Control4 API for error codes.
Parameters
response_text
- JSON or XML response from Control4, as a string.
Classes
class BadCredentials (message)
-
Expand source code
class BadCredentials(Unauthorized): """Raised when provided credentials are incorrect."""
Raised when provided credentials are incorrect.
Ancestors
- Unauthorized
- C4Exception
- builtins.Exception
- builtins.BaseException
class BadToken (message)
-
Expand source code
class BadToken(Unauthorized): """Raised when director bearer token is invalid."""
Raised when director bearer token is invalid.
Ancestors
- Unauthorized
- C4Exception
- builtins.Exception
- builtins.BaseException
class C4Exception (message)
-
Expand source code
class C4Exception(Exception): """Base error for pyControl4.""" def __init__(self, message): self.message = message
Base error for pyControl4.
Ancestors
- builtins.Exception
- builtins.BaseException
Subclasses
class InvalidCategory (message)
-
Expand source code
class InvalidCategory(C4Exception): """Raised when an invalid category is provided when calling `pyControl4.director.C4Director.getAllItemsByCategory`."""
Raised when an invalid category is provided when calling
C4Director.getAllItemsByCategory()
.Ancestors
- C4Exception
- builtins.Exception
- builtins.BaseException
class NotFound (message)
-
Expand source code
class NotFound(C4Exception): """Raised when a 404 response is recieved from the Control4 API. Occurs when the requested controller, etc. could not be found."""
Raised when a 404 response is recieved from the Control4 API. Occurs when the requested controller, etc. could not be found.
Ancestors
- C4Exception
- builtins.Exception
- builtins.BaseException
-
Expand source code
class Unauthorized(C4Exception): """Raised when unauthorized, but no other recognized details are provided. Occurs when token is invalid."""
Raised when unauthorized, but no other recognized details are provided. Occurs when token is invalid.
Ancestors
- C4Exception
- builtins.Exception
- builtins.BaseException
Subclasses