diff --git a/mygeotab/altitude/wrapper.py b/mygeotab/altitude/wrapper.py index f36f0ae..783aa7e 100644 --- a/mygeotab/altitude/wrapper.py +++ b/mygeotab/altitude/wrapper.py @@ -64,6 +64,11 @@ def _call_api(self, service_name: str, function_name: str, function_parameters: functionParameters=function_parameters, ) return results + + def _extract_errors(self, resp: dict) -> list: + """Extracts errors from myG and daas wrappers.""" + return resp.get("errors", []) or resp.get("apiResult", {}).get("errors", []) + def call_api(self, function_name: str, params: dict) -> dict: """ @@ -99,13 +104,14 @@ def create_job(self, params: dict) -> dict: function_name="createQueryJob", params=params, ) - errors = results.get("errors", []) - if errors and len(errors) > 0: - raise errors[0] + + errors = self._extract_errors(resp=results) + if errors: + raise Exception(errors[0].get("message", "Failed to create the job")) + return results["apiResult"]["results"][0] except Exception as e: logging.error(f"Exception: {e}") - logging.error(f"error: error while creating job, results: {results}") raise e def check_job_status(self, params: dict) -> DaasGetJobStatusResult: @@ -206,4 +212,4 @@ def do(self, params: dict) -> list: logging.info(f"gathering result") data = self.get_data(params) logging.info(f"data gathered") - return data + return data \ No newline at end of file