Error code standardization

test-errcode
skiffer-git 2 years ago
parent 00bd22041b
commit bac9ba000e

@ -1,21 +1,6 @@
package constant
const (
//group admin
// OrdinaryMember = 0
// GroupOwner = 1
// Administrator = 2
//group application
// Application = 0
// AgreeApplication = 1
//friend related
BlackListFlag = 1
ApplicationFriendFlag = 0
FriendFlag = 1
RefuseFriendFlag = -1
//Websocket Protocol
WSGetNewestSeq = 1001
WSPullMsgBySeqList = 1002

@ -1,10 +1,7 @@
package constant
import (
sdkws "Open_IM/pkg/proto/sdk_ws"
"context"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"gorm.io/gorm"
"strings"
@ -67,28 +64,3 @@ func ToAPIErrWithErr(err error) *ErrInfo {
}
return toDetail(err, ErrDefaultOther)
}
func SetErrorForResp(err error, commonResp *sdkws.CommonResp) {
errInfo := ToAPIErrWithErr(err)
commonResp.ErrCode = errInfo.ErrCode
commonResp.ErrMsg = errInfo.ErrMsg
commonResp.DetailErrMsg = err.Error()
}
func CommonResp2Err(resp *sdkws.CommonResp) error {
if resp.ErrCode != NoError {
return errors.New(fmt.Sprintf("call rpc error, errCode is %d, errMsg is %s, detailErrMsg is %s", resp.ErrCode, resp.ErrMsg, resp.DetailErrMsg))
}
return nil
}
func Error2CommResp(ctx context.Context, info *ErrInfo, detailErrMsg string) *sdkws.CommonResp {
err := &sdkws.CommonResp{
ErrCode: info.ErrCode,
ErrMsg: info.ErrMsg,
}
if detailErrMsg != "" {
err.DetailErrMsg = detailErrMsg
}
return err
}

@ -26,7 +26,7 @@ type FriendUser struct {
func NewFriendDB(db *gorm.DB) *Friend {
var friend Friend
friend.DB = initModel(db, friend)
friend.DB = db
return &friend
}

@ -84,7 +84,7 @@ func (u *User) GetByName(ctx context.Context, userName string, showNumber, pageN
func (u *User) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*User, count int64, err error) {
defer func() {
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userName", userName, "showNumber", showNumber, "pageNumber", pageNumber, "users", users)
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "content", content, "showNumber", showNumber, "pageNumber", pageNumber, "users", users)
}()
db := u.DB.Where(" name like ? or user_id = ? ", fmt.Sprintf("%%%s%%", content), content)
if err := db.Count(&count).Error; err != nil {

Loading…
Cancel
Save