mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
rpctypes: Error function to convert clientv3 error
This commit is contained in:
parent
bef5be42b5
commit
f613052435
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user