1-
21class DaasError :
32 def __init__ (self , error : dict ):
43 self .error = error
5- self .code = self .error ['code' ]
6- self .domain = self .error ['domain' ]
7- self .message = self .error ['message' ]
4+ self .code = self .error ["code" ]
5+ self .domain = self .error ["domain" ]
6+ self .message = self .error ["message" ]
7+
88
99NOT_FULL_API_CALL_EXCEPTION = Exception ("api return did not have all expected attributes, please retry again." )
10+
11+
1012class DaasResult :
1113 """DaasResult class, the base class for all results returned from calling our application from the gateway
1214
@@ -19,10 +21,9 @@ class DaasResult:
1921 api_result_errors (list): possible errors list that happened on the altitude application.
2022 api_result_error_message (str): possible single error message that happened on the altitude application.
2123 api_result_error (DaasError): possible single error object that happened on the altitude application.
22- errors (list): list of all the errors (gateway and altitude application) combined together.
24+ errors (list): list of all the errors (gateway and altitude application) combined together.
2325 """
2426
25-
2627 def __init__ (self , call_result : dict ):
2728
2829 if not call_result :
@@ -32,10 +33,7 @@ def __init__(self, call_result: dict):
3233 self .call_result = call_result
3334
3435 self .daas_errors = [DaasError (error ) for error in self .call_result .get ("errors" , [])]
35- self .errors = [
36- Exception (error .message ) for error in self .daas_errors
37- ]
38-
36+ self .errors = [Exception (error .message ) for error in self .daas_errors ]
3937
4038 if "apiResult" not in call_result :
4139 self .errors += [Exception ("apiResult not present" ), NOT_FULL_API_CALL_EXCEPTION ]
@@ -45,33 +43,24 @@ def __init__(self, call_result: dict):
4543 self .jobs = self .api_result ["results" ]
4644 self .job = self .jobs [0 ]
4745
48-
4946 self .api_result_errors = [DaasError (error ) for error in self .api_result .get ("errors" , [])]
5047 self .api_result_error_message = self .api_result .get ("errorMessage" , None )
5148 self .api_result_error = None
5249
50+ self .errors += [Exception (error .message ) for error in self .api_result_errors ]
5351
54-
55-
56- self .errors += [
57- Exception (error .message ) for error in self .api_result_errors
58- ]
59-
60-
61- if "error" in self .api_result and self .api_result ["error" ]:
52+ if "error" in self .api_result and self .api_result ["error" ]:
6253 self .api_result_error = DaasError (self .api_result ["error" ])
63- self .errors += [
64- Exception (self .api_result_error .message )
65- ]
54+ self .errors += [Exception (self .api_result_error .message )]
6655
67- if self . api_result_error_message and isinstance ( self . api_result_error_message , str ) and len ( self . api_result_error_message ):
68- self .errors += [
69- Exception (self .api_result_error_message )
70- ]
71- elif self . api_result_error_message and isinstance ( self . api_result_error_message , dict ):
72- self .errors += [
73- Exception (self .api_result_error_message [ "message" ])
74- ]
56+ if (
57+ self .api_result_error_message
58+ and isinstance (self .api_result_error_message , str )
59+ and len ( self . api_result_error_message )
60+ ):
61+ self .errors += [Exception ( self . api_result_error_message )]
62+ elif self . api_result_error_message and isinstance (self .api_result_error_message , dict ):
63+ self . errors += [ Exception ( self . api_result_error_message [ "message" ]) ]
7564
7665
7766class DaasGetJobStatusResult (DaasResult ):
@@ -82,23 +71,22 @@ class DaasGetJobStatusResult(DaasResult):
8271 status (dict): the status of the job
8372 state (str): the state of the job (from the status object)
8473 """
85-
86-
74+
8775 def __init__ (self , call_result : dict ):
8876 super ().__init__ (call_result )
89- self .id = self .job ['id' ]
90- self .status = self .job .get ("status" , {' state' : ' FAILED' })
77+ self .id = self .job ["id" ]
78+ self .status = self .job .get ("status" , {" state" : " FAILED" })
9179 self .state = self .status .get ("state" , "FAILED" )
80+
9281 def has_finished (self ):
93- if self .state == ' DONE' :
82+ if self .state == " DONE" :
9483 return True
95- elif self .state != ' FAILED' :
84+ elif self .state != " FAILED" :
9685 return False
97- elif self .state == ' FAILED' and self .errors and len (self .errors ) > 0 :
86+ elif self .state == " FAILED" and self .errors and len (self .errors ) > 0 :
9887 return False
9988 else :
10089 raise Exception ("got to failed state with no error, please reach out." )
101-
10290
10391
10492class DaasGetQueryResult (DaasResult ):
@@ -109,12 +97,9 @@ class DaasGetQueryResult(DaasResult):
10997 rows (list): the rows including the data
11098 pageToken (str): the token of the page
11199 """
112-
113-
100+
114101 def __init__ (self , call_result : dict ):
115102 super ().__init__ (call_result )
116- self .total_rows = self .job .get ('totalRows' , None )
117- self .rows = self .job .get ('rows' , None )
118- self .page_token = self .job .get ('pageToken' , None )
119-
120-
103+ self .total_rows = self .job .get ("totalRows" , None )
104+ self .rows = self .job .get ("rows" , None )
105+ self .page_token = self .job .get ("pageToken" , None )
0 commit comments