null pointer fix

pull/103/head
Gordon 3 years ago
parent 6dacf23312
commit aae6874928

@ -48,8 +48,12 @@ func ImportFriend(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "cImportFriend failed " + err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "cImportFriend failed " + err.Error()})
return return
} }
failedUidList := make([]string, 0)
for _, v := range RpcResp.FailedUidList {
failedUidList = append(failedUidList, v)
}
log.NewDebug(req.OperationID, "rpc importFriend success", RpcResp.CommonResp.ErrorMsg, RpcResp.CommonResp.ErrorCode, RpcResp.FailedUidList) log.NewDebug(req.OperationID, "rpc importFriend success", RpcResp.CommonResp.ErrorMsg, RpcResp.CommonResp.ErrorCode, RpcResp.FailedUidList)
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "failedUidList": RpcResp.FailedUidList}) c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "failedUidList": failedUidList})
} }
func AddFriend(c *gin.Context) { func AddFriend(c *gin.Context) {

@ -43,10 +43,14 @@ func DeleteUser(c *gin.Context) {
} }
RpcResp, err := client.DeleteUsers(context.Background(), req) RpcResp, err := client.DeleteUsers(context.Background(), req)
if err != nil { if err != nil {
log.NewError(req.OperationID, "call delete users rpc server failed", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete users rpc server failed"}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete users rpc server failed"})
return return
} }
failedUidList := make([]string, 0)
for _, v := range RpcResp.FailedUidList {
failedUidList = append(failedUidList, v)
}
log.InfoByKv("call delete user rpc server is success", params.OperationID, "resp args", RpcResp.String()) log.InfoByKv("call delete user rpc server is success", params.OperationID, "resp args", RpcResp.String())
resp := gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "failedUidList": RpcResp.FailedUidList} resp := gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "failedUidList": RpcResp.FailedUidList}
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)

@ -18,6 +18,7 @@ import (
func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) { func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
log.InfoByKv("rpc DeleteUsers arrived server", req.OperationID, "args", req.String()) log.InfoByKv("rpc DeleteUsers arrived server", req.OperationID, "args", req.String())
var resp pbUser.DeleteUsersResp var resp pbUser.DeleteUsersResp
var common pbUser.CommonResp
c, err := utils.ParseToken(req.Token) c, err := utils.ParseToken(req.Token)
if err != nil { if err != nil {
log.ErrorByKv("parse token failed", req.OperationID, "err", err.Error()) log.ErrorByKv("parse token failed", req.OperationID, "err", err.Error())
@ -30,11 +31,12 @@ func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq)
for _, uid := range req.DeleteUidList { for _, uid := range req.DeleteUidList {
err = im_mysql_model.UserDelete(uid) err = im_mysql_model.UserDelete(uid)
if err != nil { if err != nil {
resp.CommonResp.ErrorCode = 201 common.ErrorCode = 201
resp.CommonResp.ErrorMsg = "some uid deleted failed" common.ErrorMsg = "some uid deleted failed"
resp.FailedUidList = append(resp.FailedUidList, uid) resp.FailedUidList = append(resp.FailedUidList, uid)
} }
} }
resp.CommonResp = &common
return &resp, nil return &resp, nil
} }

Loading…
Cancel
Save