File tree 1 file changed +19
-6
lines changed
app/gateway/app/api/client
1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -47,27 +47,40 @@ def execute(self, data):
47
47
msg_id = 0
48
48
data ['id' ] = msg_id
49
49
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 ))
51
59
52
60
resp = self .read_line ()
61
+ # print(resp)
53
62
if not resp :
54
63
self .close ()
55
64
raise Exception ("rpc 获取数据失败, Not resp, server gone" )
56
65
57
- resp = json .loads (resp )
66
+ try :
67
+ resp = json .loads (resp )
68
+ except BaseException as e :
69
+ # todo log
70
+ raise e
58
71
59
72
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' )))
62
74
63
75
if resp .get ('error' ) is not None :
64
76
raise Exception (resp .get ('error' ))
65
77
66
- data = json .loads (resp .get ('result' ))
78
+ data = resp .get ('result' )
79
+
67
80
if data ['code' ] != '0' :
68
81
raise Exception ("rpc 获取数据失败: %s" % data ['error' ])
69
82
70
- return data
83
+ return data [ 'data' ]
71
84
72
85
def read_line (self ):
73
86
# return self.conn.makefile().readline()
You can’t perform that action at this time.
0 commit comments