package exception import ( "fmt" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) var ( // google grpc error status. OK = Errorf(0, "OK") ErrCanceled = Errorf(1, "Canceled") ErrUnknown = Errorf(2, "Unknown") ErrInvalidArgument = Errorf(3, "Invalid Argument") ErrDeadlineExceeded = Errorf(4, "Deadline Exceeded") ErrNotFound = Errorf(5, "Not Found") ErrAlreadyExists = Errorf(6, "Already Exists") ErrPermissionDenied = Errorf(7, "Permission Denied") ErrResourceExhausted = Errorf(8, "Resource Exhausted") ErrFailedPrecondition = Errorf(9, "Failed Precondition") ErrAborted = Errorf(10, "Aborted") ErrOutOfRange = Errorf(11, "Out Of Range") ErrUnimplemented = Errorf(12, "Unimplemented") ErrInternal = Errorf(13, "Internal") ErrUnavailable = Errorf(14, "Unavailable") ErrDataLoss = Errorf(15, "Data Loss") ErrUnauthenticated = Errorf(16, "Unauthenticated") ErrJSONMarshal = Errorf(17, "Marshal JSON") ErrJSONUnmarshal = Errorf(18, "Unmarshal JSON") ErrPasswd = Errorf(19, "Password Error") ErrSmsCode = Errorf(20, "SMS Code Invalid") ErrIdArgument = Errorf(30, "ID Invalid Argument") ErrIdentityArgument = Errorf(31, "Identity Invalid Argument") // coustom error status ) func Error(c uint32, msg string) error { return status.New(codes.Code(c), msg).Err() } func Errorf(c uint32, format string, a ...interface{}) error { return status.New(codes.Code(c), fmt.Sprintf(format, a...)).Err() }