Beispiel #1
0
        private static async Task <IdentityResult> TryExecuteAsync(
            Func <Task> action,
            CassandraErrorDescriber errorDescriber,
            ILogger logger)
        {
            IdentityResult result;

            try
            {
                await action();

                result = IdentityResult.Success;
            }
            catch (Exception exception)
            {
                logger.LogError(exception, "Error while executing query.");

                var type = exception.GetType();
                switch (type)
                {
                case Type _ when type == typeof(NoHostAvailableException):
                    result = IdentityResult.Failed(errorDescriber.NoHostAvailable());
                    break;

                case Type _ when type == typeof(UnavailableException):
                    result = IdentityResult.Failed(errorDescriber.Unavailable());
                    break;

                case Type _ when type == typeof(ReadTimeoutException):
                    result = IdentityResult.Failed(errorDescriber.ReadTimeout());
                    break;

                case Type _ when type == typeof(WriteTimeoutException):
                    result = IdentityResult.Failed(errorDescriber.WriteTimeout());
                    break;

                case Type _ when type == typeof(QueryValidationException):
                    result = IdentityResult.Failed(errorDescriber.QueryValidation());
                    break;

                default:
                    result = IdentityResult.Failed(errorDescriber.DefaultError(exception.Message));
                    break;
                }
            }

            return(result);
        }