refactor: errcode update

pull/476/head
Gordon 1 year ago
parent ba20fa90f7
commit 3a3784329e

@ -41,7 +41,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
func (s *authServer) UserToken(ctx context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
resp := pbAuth.UserTokenResp{}
if req.Secret != config.Config.Secret {
return nil, errs.ErrIdentity.Wrap("secret invalid")
return nil, errs.ErrNoPermission.Wrap("secret invalid")
}
if _, err := s.userRpcClient.GetUserInfo(ctx, req.UserID); err != nil {
return nil, err

@ -168,7 +168,7 @@ func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterR
}
if req.Secret != config.Config.Secret {
log.ZDebug(ctx, "UserRegister", config.Config.Secret, req.Secret)
return nil, errs.ErrIdentity.Wrap("secret invalid")
return nil, errs.ErrNoPermission.Wrap("secret invalid")
}
if utils.DuplicateAny(req.Users, func(e *sdkws.UserInfo) string { return e.UserID }) {
return nil, errs.ErrArgs.Wrap("userID repeated")

@ -68,7 +68,7 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
if opUserID == ownerUserID {
return nil
}
return errs.ErrIdentity.Wrap(utils.GetSelfFuncName())
return errs.ErrNoPermission.Wrap(utils.GetSelfFuncName())
}
func IsAppManagerUid(ctx context.Context) bool {
@ -79,7 +79,7 @@ func CheckAdmin(ctx context.Context) error {
if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) {
return nil
}
return errs.ErrIdentity.Wrap(fmt.Sprintf("user %s is not admin userID", mcontext.GetOpUserID(ctx)))
return errs.ErrNoPermission.Wrap(fmt.Sprintf("user %s is not admin userID", mcontext.GetOpUserID(ctx)))
}
func ParseRedisInterfaceToken(redisToken interface{}) (*Claims, error) {

@ -22,17 +22,12 @@ const (
// 通用错误码
const (
NoError = 0 //无错误
DatabaseError = 90002 //redis/mysql等db错误
NetworkError = 90004 //网络错误
IdentityError = 90008 // 身份错误 非管理员token且token中userID与请求userID不一致
GRPCConnIsNil = 90006 //grpc连接空
DefaultOtherError = 90006 //其他错误
DataError = 90007 //数据错误
ConfigError = 90009
CallbackError = 80000
RelationshipAlreadyError = 92001 //已经是好友关系(或者黑名单)
NotRelationshipYetError = 92002 //不是好友关系(或者黑名单)
NoError = 0 //无错误
DatabaseError = 90002 //redis/mysql等db错误
NetworkError = 90004 //网络错误
DataError = 90007 //数据错误
ConfigError = 90009
CallbackError = 80000
//通用错误码
ServerInternalError = 500 //服务器内部错误
@ -59,9 +54,10 @@ const (
GroupRequestHandled = 1210
// 关系链错误码
CanNotAddYourselfError = 1301 //不能添加自己为好友
BlockedByPeer = 1302 //被对方拉黑
NotPeersFriend = 1303 //不是对方的好友
CanNotAddYourselfError = 1301 //不能添加自己为好友
BlockedByPeer = 1302 //被对方拉黑
NotPeersFriend = 1303 //不是对方的好友
RelationshipAlreadyError = 1304 //已经是好友关系(或者黑名单)
// 消息错误码
MessageHasReadDisable = 1401

@ -2,11 +2,10 @@ package errs
var (
ErrArgs = NewCodeError(ArgsError, "ArgsError")
ErrNoPermission = NewCodeError(NoPermissionError, "NoPermissionError")
ErrDatabase = NewCodeError(DatabaseError, "DatabaseError")
ErrInternalServer = NewCodeError(ServerInternalError, "ServerInternalError")
ErrNetwork = NewCodeError(NetworkError, "NetworkError")
ErrNoPermission = NewCodeError(NoPermissionError, "NoPermissionError")
ErrIdentity = NewCodeError(IdentityError, "IdentityError")
ErrCallback = NewCodeError(CallbackError, "CallbackError")
ErrCallbackContinue = NewCodeError(CallbackError, "ErrCallbackContinue")
@ -17,10 +16,6 @@ var (
ErrRecordNotFound = NewCodeError(RecordNotFoundError, "RecordNotFoundError")
ErrRelationshipAlready = NewCodeError(RelationshipAlreadyError, "RelationshipAlreadyError")
ErrNotRelationshipYet = NewCodeError(NotRelationshipYetError, "NotRelationshipYetError")
ErrCanNotAddYourself = NewCodeError(CanNotAddYourselfError, "CanNotAddYourselfError")
ErrOnlyOneOwner = NewCodeError(OnlyOneOwnerError, "OnlyOneOwnerError")
ErrInGroupAlready = NewCodeError(InGroupAlreadyError, "InGroupAlreadyError")
ErrNotInGroupYet = NewCodeError(NotInGroupYetError, "NotInGroupYetError")
@ -30,7 +25,6 @@ var (
ErrGroupTypeNotSupport = NewCodeError(GroupTypeNotSupport, "")
ErrGroupNoOwner = NewCodeError(GroupNoOwner, "ErrGroupNoOwner")
ErrDefaultOther = NewCodeError(DefaultOtherError, "DefaultOtherError")
ErrData = NewCodeError(DataError, "DataError")
ErrTokenExpired = NewCodeError(TokenExpiredError, "TokenExpiredError")
ErrTokenInvalid = NewCodeError(TokenInvalidError, "TokenInvalidError") //
@ -45,9 +39,10 @@ var (
ErrMessageHasReadDisable = NewCodeError(MessageHasReadDisable, "MessageHasReadDisable")
ErrBlockedByPeer = NewCodeError(BlockedByPeer, "BlockedByPeer")
//不是对方的好友
ErrNotPeersFriend = NewCodeError(NotPeersFriend, "NotPeersFriend")
ErrRelationshipAlready = NewCodeError(RelationshipAlreadyError, "RelationshipAlreadyError")
ErrCanNotAddYourself = NewCodeError(CanNotAddYourselfError, "CanNotAddYourselfError")
ErrBlockedByPeer = NewCodeError(BlockedByPeer, "BlockedByPeer")
ErrNotPeersFriend = NewCodeError(NotPeersFriend, "NotPeersFriend")
ErrMutedInGroup = NewCodeError(MutedInGroup, "MutedInGroup")
ErrMutedGroup = NewCodeError(MutedGroup, "MutedGroup")

Loading…
Cancel
Save