|
|
|
@ -24,52 +24,53 @@ func (e ErrInfo) Code() int32 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
ErrNone = ErrInfo{0, ""}
|
|
|
|
|
ErrArgs = ErrInfo{ArgsError, "ArgsError"}
|
|
|
|
|
ErrDatabase = ErrInfo{DatabaseError, "DatabaseError"}
|
|
|
|
|
ErrInternalServer = ErrInfo{ServerInternalError, "ServerInternalError"}
|
|
|
|
|
ErrNetwork = ErrInfo{NetworkError, "NetworkError"}
|
|
|
|
|
ErrNoPermission = ErrInfo{NoPermissionError, "NoPermissionError"}
|
|
|
|
|
|
|
|
|
|
ErrUserIDNotFound = ErrInfo{UserIDNotFoundError, "UserIDNotFoundError"}
|
|
|
|
|
ErrGroupIDNotFound = ErrInfo{GroupIDNotFoundError, "GroupIDNotFoundError"}
|
|
|
|
|
|
|
|
|
|
ErrRecordNotFound = ErrInfo{RecordNotFoundError, "RecordNotFoundError"}
|
|
|
|
|
|
|
|
|
|
ErrRelationshipAlready = ErrInfo{RelationshipAlreadyError, "RelationshipAlreadyError"}
|
|
|
|
|
ErrNotRelationshipYet = ErrInfo{NotRelationshipYetError, "NotRelationshipYetError"}
|
|
|
|
|
|
|
|
|
|
ErrOnlyOneOwner = ErrInfo{OnlyOneOwnerError, "OnlyOneOwnerError"}
|
|
|
|
|
ErrInGroupAlready = ErrInfo{InGroupAlreadyError, "InGroupAlreadyError"}
|
|
|
|
|
ErrNotInGroupYet = ErrInfo{NotInGroupYetError, "NotInGroupYetError"}
|
|
|
|
|
ErrDismissedAlready = ErrInfo{DismissedAlreadyError, "DismissedAlreadyError"}
|
|
|
|
|
ErrOwnerNotAllowedQuit = ErrInfo{OwnerNotAllowedQuitError, "OwnerNotAllowedQuitError"}
|
|
|
|
|
ErrRegisteredAlready = ErrInfo{RegisteredAlreadyError, "RegisteredAlreadyError"}
|
|
|
|
|
|
|
|
|
|
ErrDefaultOther = ErrInfo{DefaultOtherError, "DefaultOtherError"}
|
|
|
|
|
ErrData = ErrInfo{DataError, "DataError"}
|
|
|
|
|
ErrTokenExpired = ErrInfo{TokenExpiredError, "TokenExpiredError"}
|
|
|
|
|
ErrTokenInvalid = ErrInfo{TokenInvalidError, "TokenInvalidError"} //
|
|
|
|
|
ErrTokenMalformed = ErrInfo{TokenMalformedError, "TokenMalformedError"} //格式错误
|
|
|
|
|
ErrTokenNotValidYet = ErrInfo{TokenNotValidYetError, "TokenNotValidYetError"} //还未生效
|
|
|
|
|
ErrTokenUnknown = ErrInfo{TokenUnknownError, "TokenUnknownError"} //未知错误
|
|
|
|
|
ErrTokenKicked = ErrInfo{TokenKickedError, "TokenKickedError"}
|
|
|
|
|
ErrTokenNotExist = ErrInfo{TokenNotExistError, "TokenNotExistError"} //在redis中不存在
|
|
|
|
|
ErrTokenDifferentPlatformID = ErrInfo{TokenDifferentPlatformIDError, "TokenDifferentPlatformIDError"}
|
|
|
|
|
ErrTokenDifferentUserID = ErrInfo{TokenDifferentUserIDError, "TokenDifferentUserIDError"}
|
|
|
|
|
ErrNone = ErrInfo{0, "", ""}
|
|
|
|
|
ErrArgs = ErrInfo{ArgsError, "ArgsError", ""}
|
|
|
|
|
ErrDatabase = ErrInfo{DatabaseError, "DatabaseError", ""}
|
|
|
|
|
ErrInternalServer = ErrInfo{ServerInternalError, "ServerInternalError", ""}
|
|
|
|
|
ErrNetwork = ErrInfo{NetworkError, "NetworkError", ""}
|
|
|
|
|
ErrNoPermission = ErrInfo{NoPermissionError, "NoPermissionError", ""}
|
|
|
|
|
|
|
|
|
|
ErrUserIDNotFound = ErrInfo{UserIDNotFoundError, "UserIDNotFoundError", ""}
|
|
|
|
|
ErrGroupIDNotFound = ErrInfo{GroupIDNotFoundError, "GroupIDNotFoundError", ""}
|
|
|
|
|
|
|
|
|
|
ErrRecordNotFound = ErrInfo{RecordNotFoundError, "RecordNotFoundError", ""}
|
|
|
|
|
|
|
|
|
|
ErrRelationshipAlready = ErrInfo{RelationshipAlreadyError, "RelationshipAlreadyError", ""}
|
|
|
|
|
ErrNotRelationshipYet = ErrInfo{NotRelationshipYetError, "NotRelationshipYetError", ""}
|
|
|
|
|
|
|
|
|
|
ErrOnlyOneOwner = ErrInfo{OnlyOneOwnerError, "OnlyOneOwnerError", ""}
|
|
|
|
|
ErrInGroupAlready = ErrInfo{InGroupAlreadyError, "InGroupAlreadyError", ""}
|
|
|
|
|
ErrNotInGroupYet = ErrInfo{NotInGroupYetError, "NotInGroupYetError", ""}
|
|
|
|
|
ErrDismissedAlready = ErrInfo{DismissedAlreadyError, "DismissedAlreadyError", ""}
|
|
|
|
|
ErrOwnerNotAllowedQuit = ErrInfo{OwnerNotAllowedQuitError, "OwnerNotAllowedQuitError", ""}
|
|
|
|
|
ErrRegisteredAlready = ErrInfo{RegisteredAlreadyError, "RegisteredAlreadyError", ""}
|
|
|
|
|
|
|
|
|
|
ErrDefaultOther = ErrInfo{DefaultOtherError, "DefaultOtherError", ""}
|
|
|
|
|
ErrData = ErrInfo{DataError, "DataError", ""}
|
|
|
|
|
ErrTokenExpired = ErrInfo{TokenExpiredError, "TokenExpiredError", ""}
|
|
|
|
|
ErrTokenInvalid = ErrInfo{TokenInvalidError, "TokenInvalidError", ""} //
|
|
|
|
|
ErrTokenMalformed = ErrInfo{TokenMalformedError, "TokenMalformedError", ""} //格式错误
|
|
|
|
|
ErrTokenNotValidYet = ErrInfo{TokenNotValidYetError, "TokenNotValidYetError", ""} //还未生效
|
|
|
|
|
ErrTokenUnknown = ErrInfo{TokenUnknownError, "TokenUnknownError", ""} //未知错误
|
|
|
|
|
ErrTokenKicked = ErrInfo{TokenKickedError, "TokenKickedError", ""}
|
|
|
|
|
ErrTokenNotExist = ErrInfo{TokenNotExistError, "TokenNotExistError", ""} //在redis中不存在
|
|
|
|
|
ErrTokenDifferentPlatformID = ErrInfo{TokenDifferentPlatformIDError, "TokenDifferentPlatformIDError", ""}
|
|
|
|
|
ErrTokenDifferentUserID = ErrInfo{TokenDifferentUserIDError, "TokenDifferentUserIDError", ""}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//var (
|
|
|
|
|
// ErrGroupStatusDismissed = errors.New("group dismissed")
|
|
|
|
|
// ErrNoGroupOwner = errors.New("no group owner")
|
|
|
|
|
//)
|
|
|
|
|
func toDetail(err error, info ErrInfo) ErrInfo {
|
|
|
|
|
errInfo := info
|
|
|
|
|
errInfo.WrapErrMsg = err.Error()
|
|
|
|
|
return errInfo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ToAPIErrWithErr(err error) ErrInfo {
|
|
|
|
|
switch {
|
|
|
|
|
case errors.Is(err, gorm.ErrRecordNotFound):
|
|
|
|
|
return ErrRecordNotFound
|
|
|
|
|
return toDetail(err, ErrRecordNotFound)
|
|
|
|
|
case errors.Is(err, ErrArgs):
|
|
|
|
|
return ErrArgs
|
|
|
|
|
return toDetail(err, ErrArgs)
|
|
|
|
|
case errors.Is(err, ErrDatabase):
|
|
|
|
|
return ErrDatabase
|
|
|
|
|
}
|
|
|
|
|