rpctypes: Error function to convert clientv3 error

This commit is contained in:
Gyu-Ho Lee 2016-04-28 12:16:13 -07:00
parent bef5be42b5
commit f613052435

View File

@ -42,4 +42,40 @@ var (
ErrRoleAlreadyExist = grpc.Errorf(codes.FailedPrecondition, "etcdserver: role name already exists")
ErrRoleNotFound = grpc.Errorf(codes.FailedPrecondition, "etcdserver: role name not found")
ErrAuthFailed = grpc.Errorf(codes.InvalidArgument, "etcdserver: authentication failed, invalid user ID or password")
errStringToError = map[string]error{
grpc.ErrorDesc(ErrEmptyKey): ErrEmptyKey,
grpc.ErrorDesc(ErrTooManyOps): ErrTooManyOps,
grpc.ErrorDesc(ErrDuplicateKey): ErrDuplicateKey,
grpc.ErrorDesc(ErrCompacted): ErrCompacted,
grpc.ErrorDesc(ErrFutureRev): ErrFutureRev,
grpc.ErrorDesc(ErrNoSpace): ErrNoSpace,
grpc.ErrorDesc(ErrLeaseNotFound): ErrLeaseNotFound,
grpc.ErrorDesc(ErrLeaseExist): ErrLeaseExist,
grpc.ErrorDesc(ErrMemberExist): ErrMemberExist,
grpc.ErrorDesc(ErrPeerURLExist): ErrPeerURLExist,
grpc.ErrorDesc(ErrMemberBadURLs): ErrMemberBadURLs,
grpc.ErrorDesc(ErrMemberNotFound): ErrMemberNotFound,
grpc.ErrorDesc(ErrRequestTooLarge): ErrRequestTooLarge,
grpc.ErrorDesc(ErrUserAlreadyExist): ErrUserAlreadyExist,
grpc.ErrorDesc(ErrUserNotFound): ErrUserNotFound,
grpc.ErrorDesc(ErrRoleAlreadyExist): ErrRoleAlreadyExist,
grpc.ErrorDesc(ErrRoleNotFound): ErrRoleNotFound,
grpc.ErrorDesc(ErrAuthFailed): ErrAuthFailed,
}
)
func Error(err error) error {
if err == nil {
return nil
}
v, ok := errStringToError[err.Error()]
if !ok {
return err
}
return v
}