File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import requests
77from .const import DEFAULT_TIMEOUT
88from .customerlogging import logger
9+ from .exceptions import ApiRequestException
910import json
1011import hmac
1112import hashlib
@@ -115,7 +116,7 @@ def __request(
115116 logger .debug ("response before decrypt ret = %s" , ret )
116117
117118 if not ret .get ("success" ):
118- raise Exception ( f"network error:( { ret [' code' ] } ) { ret [' msg' ] } " )
119+ raise ApiRequestException ( error_code = ret [" code" ], error_message = ret [" msg" ] )
119120
120121 result = _aex_gcm_decrypt (ret .get ("result" ), secret )
121122 try :
Original file line number Diff line number Diff line change 1+ class TuyaSDKException (Exception ):
2+ """Base exception for the SDK"""
3+
4+
5+ class ApiRequestException (TuyaSDKException ):
6+ """Exception raised when the server returned an error."""
7+
8+ def __init__ (
9+ self ,
10+ * ,
11+ error_code : str ,
12+ error_message : str ,
13+ ) -> None :
14+ """Initialize exception."""
15+ super ().__init__ (f"network error:({ error_code } ) { error_message } " )
16+ self .error_code = error_code
17+ self .error_message = error_message
You can’t perform that action at this time.
0 commit comments