@@ -64,6 +64,11 @@ def _call_api(self, service_name: str, function_name: str, function_parameters:
6464 functionParameters = function_parameters ,
6565 )
6666 return results
67+
68+ def _extract_errors (self , resp : dict ) -> list :
69+ """Extracts errors from myG and daas wrappers."""
70+ return resp .get ("errors" , []) or resp .get ("apiResult" , {}).get ("errors" , [])
71+
6772
6873 def call_api (self , function_name : str , params : dict ) -> dict :
6974 """
@@ -99,13 +104,14 @@ def create_job(self, params: dict) -> dict:
99104 function_name = "createQueryJob" ,
100105 params = params ,
101106 )
102- errors = results .get ("errors" , [])
103- if errors and len (errors ) > 0 :
104- raise errors [0 ]
107+
108+ errors = self ._extract_errors (resp = results )
109+ if errors :
110+ raise Exception (errors [0 ].get ("message" , "Failed to create the job" ))
111+
105112 return results ["apiResult" ]["results" ][0 ]
106113 except Exception as e :
107114 logging .error (f"Exception: { e } " )
108- logging .error (f"error: error while creating job, results: { results } " )
109115 raise e
110116
111117 def check_job_status (self , params : dict ) -> DaasGetJobStatusResult :
@@ -206,4 +212,4 @@ def do(self, params: dict) -> list:
206212 logging .info (f"gathering result" )
207213 data = self .get_data (params )
208214 logging .info (f"data gathered" )
209- return data
215+ return data
0 commit comments