refactor: errcode update

pull/476/head
Gordon 2 years 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) { func (s *authServer) UserToken(ctx context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
resp := pbAuth.UserTokenResp{} resp := pbAuth.UserTokenResp{}
if req.Secret != config.Config.Secret { 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 { if _, err := s.userRpcClient.GetUserInfo(ctx, req.UserID); err != nil {
return nil, err return nil, err

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

@ -68,7 +68,7 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
if opUserID == ownerUserID { if opUserID == ownerUserID {
return nil return nil
} }
return errs.ErrIdentity.Wrap(utils.GetSelfFuncName()) return errs.ErrNoPermission.Wrap(utils.GetSelfFuncName())
} }
func IsAppManagerUid(ctx context.Context) bool { 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) { if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) {
return nil 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) { func ParseRedisInterfaceToken(redisToken interface{}) (*Claims, error) {

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

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

Loading…
Cancel
Save