Skip to content

Commit 2462b84

Browse files
committed
rpc
1 parent d329406 commit 2462b84

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

app/gateway/app/api/client/example.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,40 @@ def execute(self, data):
4747
msg_id = 0
4848
data['id'] = msg_id
4949
msg = json.dumps(data)
50-
self.conn.sendall(msg.encode())
50+
51+
try:
52+
self.conn.sendall(msg.encode())
53+
except BrokenPipeError as e:
54+
self.close()
55+
raise e
56+
except BaseException as e:
57+
self.close()
58+
raise Exception("rpc send message failed, error: " + str(e))
5159

5260
resp = self.read_line()
61+
# print(resp)
5362
if not resp:
5463
self.close()
5564
raise Exception("rpc 获取数据失败, Not resp, server gone")
5665

57-
resp = json.loads(resp)
66+
try:
67+
resp = json.loads(resp)
68+
except BaseException as e:
69+
# todo log
70+
raise e
5871

5972
if resp.get('id') != msg_id:
60-
raise Exception("expected id=%s, received id=%s: %s"
61-
% (msg_id, resp.get('id'), resp.get('error')))
73+
raise Exception("expected id=%s, received id=%s: %s" % (msg_id, resp.get('id'), resp.get('error')))
6274

6375
if resp.get('error') is not None:
6476
raise Exception(resp.get('error'))
6577

66-
data = json.loads(resp.get('result'))
78+
data = resp.get('result')
79+
6780
if data['code'] != '0':
6881
raise Exception("rpc 获取数据失败: %s" % data['error'])
6982

70-
return data
83+
return data['data']
7184

7285
def read_line(self):
7386
# return self.conn.makefile().readline()

0 commit comments

Comments
 (0)