Add optional error code to exceptions (#585)

This commit is contained in:
sdb9696
2023-12-20 19:16:23 +00:00
committed by GitHub
parent 6819c746d7
commit b66347116f
3 changed files with 22 additions and 8 deletions

View File

@@ -186,12 +186,12 @@ class SmartProtocol(TPLinkProtocol):
if method := resp_dict.get("method"):
msg += f" for method: {method}"
if error_code in SMART_TIMEOUT_ERRORS:
raise TimeoutException(msg)
raise TimeoutException(msg, error_code=error_code)
if error_code in SMART_RETRYABLE_ERRORS:
raise RetryableException(msg)
raise RetryableException(msg, error_code=error_code)
if error_code in SMART_AUTHENTICATION_ERRORS:
raise AuthenticationException(msg)
raise SmartDeviceException(msg)
raise AuthenticationException(msg, error_code=error_code)
raise SmartDeviceException(msg, error_code=error_code)
async def close(self) -> None:
"""Close the protocol."""