@@ -40,7 +40,8 @@ func register(c *candy.CandyClient, reader *bufio.Reader) {
4040
4141 id , err := c .Register (userName , userPassword )
4242 if err != nil {
43- log .Errorf ("Register error:%v" , err )
43+ e := candy .ErrorParse (err .Error ())
44+ log .Errorf ("Register code:%v error:%v" , e .Code , e .Msg )
4445 return
4546 }
4647
@@ -60,7 +61,8 @@ func login(c *candy.CandyClient, reader *bufio.Reader) {
6061
6162 id , err := c .Login (userName , userPassword )
6263 if err != nil {
63- log .Errorf ("Login error:%v" , err )
64+ e := candy .ErrorParse (err .Error ())
65+ log .Errorf ("Login code:%v error:%v" , e .Code , e .Msg )
6466 return
6567 }
6668
@@ -72,7 +74,8 @@ func logout(c *candy.CandyClient, reader *bufio.Reader) {
7274 fmt .Println ("================注销=======================" )
7375 err := c .Logout ()
7476 if err != nil {
75- log .Errorf ("Logout error:%v" , err )
77+ e := candy .ErrorParse (err .Error ())
78+ log .Errorf ("Logout code:%v error:%v" , e .Code , e .Msg )
7679 return
7780 }
7881
@@ -91,7 +94,8 @@ func updateUserInfo(c *candy.CandyClient, reader *bufio.Reader) {
9194
9295 id , err := c .UpdateUserInfo (userName , nickName , nil )
9396 if err != nil {
94- log .Errorf ("updateUserInfo error:%v" , err )
97+ e := candy .ErrorParse (err .Error ())
98+ log .Errorf ("updateUserInfo code:%v error:%v" , e .Code , e .Msg )
9599 return
96100 }
97101
@@ -107,13 +111,15 @@ func getUserInfoByName(c *candy.CandyClient, reader *bufio.Reader) {
107111
108112 data , err := c .GetUserInfoByName (userName )
109113 if err != nil {
110- log .Errorf ("getUserInfo error:%v" , err )
114+ e := candy .ErrorParse (err .Error ())
115+ log .Errorf ("getUserInfo code:%v error:%v" , e .Code , e .Msg )
111116 return
112117 }
113118
114119 user , err := candy .DecodeUserInfo ([]byte (data ))
115120 if err != nil {
116- log .Errorf ("Decode UserInfo error:%v" , err )
121+ e := candy .ErrorParse (err .Error ())
122+ log .Errorf ("Decode UserInfo code:%v error:%v" , e .Code , e .Msg )
117123 return
118124 }
119125
@@ -136,13 +142,15 @@ func getUserInfoByID(c *candy.CandyClient, reader *bufio.Reader) {
136142
137143 data , err := c .GetUserInfoByID (id )
138144 if err != nil {
139- log .Errorf ("getUserInfoByID error:%v" , err )
145+ e := candy .ErrorParse (err .Error ())
146+ log .Errorf ("getUserInfoByID code:%v error:%v" , e .Code , e .Msg )
140147 return
141148 }
142149
143150 user , err := candy .DecodeUserInfo ([]byte (data ))
144151 if err != nil {
145- log .Errorf ("Decode UserInfo error:%v" , err )
152+ e := candy .ErrorParse (err .Error ())
153+ log .Errorf ("Decode UserInfo code:%v error:%v" , e .Code , e .Msg )
146154 return
147155 }
148156
@@ -159,13 +167,15 @@ func findUser(c *candy.CandyClient, reader *bufio.Reader) {
159167
160168 data , err := c .FindUser (userName )
161169 if err != nil {
162- log .Errorf ("findUser error:%v" , err )
170+ e := candy .ErrorParse (err .Error ())
171+ log .Errorf ("findUser code:%v error:%v" , e .Code , e .Msg )
163172 return
164173 }
165174
166175 userList , err := candy .DecodeUserList ([]byte (data ))
167176 if err != nil {
168- log .Errorf ("Decode UserList error:%v" , err )
177+ e := candy .ErrorParse (err .Error ())
178+ log .Errorf ("Decode UserList code:%v error:%v" , e .Code , e .Msg )
169179 return
170180 }
171181
@@ -186,7 +196,8 @@ func addFriend(c *candy.CandyClient, reader *bufio.Reader) {
186196
187197 id , err := strconv .ParseInt (userID , 10 , 64 )
188198 if err != nil {
189- log .Errorf ("Parse int error:%v" , err )
199+ e := candy .ErrorParse (err .Error ())
200+ log .Errorf ("Parse int code:%v error:%v" , e .Code , e .Msg )
190201 return
191202 }
192203
@@ -196,7 +207,8 @@ func addFriend(c *candy.CandyClient, reader *bufio.Reader) {
196207
197208 confirm , err := c .AddFriend (id , true , msg )
198209 if err != nil {
199- log .Errorf ("addFriend error:%v" , err )
210+ e := candy .ErrorParse (err .Error ())
211+ log .Errorf ("addFriend code:%v error:%v" , e .Code , e .Msg )
200212 return
201213 }
202214
@@ -212,7 +224,8 @@ func newMessage(c *candy.CandyClient, reader *bufio.Reader) {
212224
213225 from , err := strconv .ParseInt (userID , 10 , 64 )
214226 if err != nil {
215- log .Errorf ("Parse int error:%v" , err )
227+ e := candy .ErrorParse (err .Error ())
228+ log .Errorf ("Parse int code:%v error:%v" , e .Code , e .Msg )
216229 return
217230 }
218231
@@ -222,7 +235,8 @@ func newMessage(c *candy.CandyClient, reader *bufio.Reader) {
222235
223236 user , err := strconv .ParseInt (userID , 10 , 64 )
224237 if err != nil {
225- log .Errorf ("Parse int error:%v" , err )
238+ e := candy .ErrorParse (err .Error ())
239+ log .Errorf ("Parse int code:%v error:%v" , e .Code , e .Msg )
226240 return
227241 }
228242
@@ -232,7 +246,8 @@ func newMessage(c *candy.CandyClient, reader *bufio.Reader) {
232246
233247 err = c .SendMessage (from , 0 , user , msg )
234248 if err != nil {
235- log .Errorf ("send message error:%v" , err )
249+ e := candy .ErrorParse (err .Error ())
250+ log .Errorf ("send message code:%v error:%v" , e .Code , e .Msg )
236251 return
237252 }
238253
@@ -248,7 +263,8 @@ func createGroup(c *candy.CandyClient, reader *bufio.Reader) {
248263
249264 gid , err := c .CreateGroup (groupName )
250265 if err != nil {
251- log .Errorf ("createGroup error:%v" , err )
266+ e := candy .ErrorParse (err .Error ())
267+ log .Errorf ("createGroup code:%v error:%v" , e .Code , e .Msg )
252268 return
253269 }
254270
@@ -261,13 +277,15 @@ func loadGroupList(c *candy.CandyClient, reader *bufio.Reader) {
261277
262278 data , err := c .LoadGroupList ()
263279 if err != nil {
264- log .Errorf ("loadGroupList error:%v" , err )
280+ e := candy .ErrorParse (err .Error ())
281+ log .Errorf ("loadGroupList code:%v error:%v" , e .Code , e .Msg )
265282 return
266283 }
267284
268285 gList , err := candy .DecodeGroupList ([]byte (data ))
269286 if err != nil {
270- log .Errorf ("Decode GroupList error:%v" , err )
287+ e := candy .ErrorParse (err .Error ())
288+ log .Errorf ("Decode GroupList code:%v error:%v" , e .Code , e .Msg )
271289 return
272290 }
273291
@@ -284,13 +302,15 @@ func loadFriendList(c *candy.CandyClient, reader *bufio.Reader) {
284302
285303 data , err := c .LoadFriendList ()
286304 if err != nil {
287- log .Errorf ("loadGroupList error:%v" , err )
305+ e := candy .ErrorParse (err .Error ())
306+ log .Errorf ("loadGroupList code:%v error:%v" , e .Code , e .Msg )
288307 return
289308 }
290309
291310 fList , err := candy .DecodeFriendList ([]byte (data ))
292311 if err != nil {
293- log .Errorf ("Decode FriendList error:%v" , err )
312+ e := candy .ErrorParse (err .Error ())
313+ log .Errorf ("Decode FriendList code:%v error:%v" , e .Code , e .Msg )
294314 return
295315 }
296316
@@ -314,7 +334,8 @@ func updateUserPasswd(c *candy.CandyClient, reader *bufio.Reader) {
314334
315335 id , err := c .UpdateUserPassword (user , pwd )
316336 if err != nil {
317- log .Errorf ("UpdateUserPassword error:%v" , err )
337+ e := candy .ErrorParse (err .Error ())
338+ log .Errorf ("UpdateUserPassword code:%v error:%v" , e .Code , e .Msg )
318339 return
319340 }
320341 log .Debugf ("UpdateUserPassword success, id:%v" , id )
@@ -334,6 +355,11 @@ func (c *cmdClient) OnError(msg string) {
334355 fmt .Printf ("rpc error:%s\n " , msg )
335356}
336357
358+ // OnHealth 连接恢复
359+ func (c * cmdClient ) OnHealth () {
360+ fmt .Printf ("connection recovery\n " )
361+ }
362+
337363// OnUnHealth 连接异常
338364func (c * cmdClient ) OnUnHealth (msg string ) {
339365 fmt .Printf ("connection UnHealth, msg:%v\n " , msg )
0 commit comments