Skip to content

Commit

Permalink
fix: fix error condition logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
mo3et committed Jun 14, 2024
1 parent 68da59a commit 8275384
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions internal/api/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/openimsdk/chat/pkg/common/constant"
"github.com/openimsdk/chat/pkg/common/imapi"
"github.com/openimsdk/chat/pkg/common/mctx"
"github.com/openimsdk/chat/pkg/eerrs"
"github.com/openimsdk/chat/pkg/protocol/admin"
chatpb "github.com/openimsdk/chat/pkg/protocol/chat"
constantpb "github.com/openimsdk/protocol/constant"
Expand Down Expand Up @@ -100,18 +101,23 @@ func (o *Api) RegisterUser(c *gin.Context) {
// if phone exist, don't return err, just a condition.
checkResp, err := o.chatClient.CheckPhoneNumberExist(rpcCtx, &chatpb.CheckPhoneNumberExistReq{PhoneNumber: req.User.PhoneNumber})
if err != nil {
isUserNotExist, err := o.imApiCaller.AccountCheckSingle(apiCtx, checkResp.Userid)
if err != nil {
apiresp.GinError(c, err)
return
}
// if User is not exist in SDK server. You need delete this user and register new user again.
if isUserNotExist {
_, err := o.adminClient.DelAdminAccount(rpcCtx, &admin.DelAdminAccountReq{UserIDs: []string{checkResp.Userid}})
if err == eerrs.ErrAccountAlreadyRegister.Wrap() {
isUserNotExist, err := o.imApiCaller.AccountCheckSingle(apiCtx, checkResp.Userid)
if err != nil {
apiresp.GinError(c, err)
return
}
// if User is not exist in SDK server. You need delete this user and register new user again.
if isUserNotExist {
_, err := o.adminClient.DelAdminAccount(rpcCtx, &admin.DelAdminAccountReq{UserIDs: []string{checkResp.Userid}})
if err != nil {
apiresp.GinError(c, err)
return
}
}
} else {
apiresp.GinError(c, err)
return
}
}

Expand Down

0 comments on commit 8275384

Please sign in to comment.