diff --git a/pyprojects/secretnote/src/secretnote/server/services/broker/manager.py b/pyprojects/secretnote/src/secretnote/server/services/broker/manager.py index d982384..5fe9223 100644 --- a/pyprojects/secretnote/src/secretnote/server/services/broker/manager.py +++ b/pyprojects/secretnote/src/secretnote/server/services/broker/manager.py @@ -44,6 +44,9 @@ async def request(self, url: str, method="GET", body=None): print("Error: " + str(e)) def get_request_status(self, response): + if response is None: + return 500, "no response found." + code = 0 message = "" status = response.get("status", None) @@ -70,7 +73,7 @@ async def create_project(self, project: Dict[str, Any], address: str) -> str: ) code, message = self.get_request_status(response) - if code != 0: + if response is None or code != 0: raise Exception(message) return response.get("project_id", "") @@ -85,7 +88,7 @@ async def get_project_list(self, address: str) -> List[Dict[str, Any]]: ) code, message = self.get_request_status(response) - if code != 0: + if response is None or code != 0: raise Exception(message) return response.get("projects", []) @@ -100,12 +103,12 @@ async def get_project_info(self, project_id: str, address: str) -> Dict[str, Any ) code, message = self.get_request_status(response) - if code != 0: + if response is None or code != 0: raise Exception(message) project = response.get("projects", []) - return project[0] if len(project) > 0 else None + return project[0] if len(project) > 0 else None # type: ignore async def get_invitation_list( self, party: str, address: str @@ -119,7 +122,7 @@ async def get_invitation_list( ) code, message = self.get_request_status(response) - if code != 0: + if response is None or code != 0: raise Exception(message) invite_list = response.get("invitations", []) @@ -177,7 +180,7 @@ async def get_table_list( ) code, message = self.get_request_status(response) - if code != 0: + if response is None or code != 0: raise Exception(message) return response.get("tables", []) @@ -230,7 +233,7 @@ async def get_table_info( ) code, message = self.get_request_status(response) - if code != 0: + if response is None or code != 0: raise Exception(message) table = response.get("tables", []) @@ -252,7 +255,7 @@ async def get_ccl_list( ) code, message = self.get_request_status(response) - if code != 0: + if response is None or code != 0: raise Exception(message) return response.get("column_control_list", []) @@ -304,12 +307,13 @@ async def query(self, project_id: str, query: str, address: str) -> List[Any]: method="POST", body=body, ) + code, message = self.get_request_status(response) - if code != 0: + if response is None or code != 0: raise Exception(message) - return response.get("out_columns", []) + return response.get("result").get("out_columns", []) async def create_query_job(self, project_id: str, address: str, query: str) -> str: url = f"{address}{BROKER_SERVICE_PATH['submit_query']}" @@ -324,7 +328,7 @@ async def create_query_job(self, project_id: str, address: str, query: str) -> s ) code, message = self.get_request_status(response) - if code != 0: + if response is None or code != 0: raise Exception(message) return response.get("job_id", "") @@ -339,7 +343,7 @@ async def get_job_result(self, job_id: str, address: str) -> List[Any]: ) code, message = self.get_request_status(response) - if code != 0: + if response is None or code != 0: raise Exception(message) return response.get("out_columns", [])