コード例 #1
0
 public static Task <ApiResponse <T> > OnError <T, TOnError>(
     this Task <ApiResponse <T> > source,
     TypeErrorPredicate errorPredicate,
     Func <Error, Task <ApiResponse <TOnError> > > onError
     )
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Switch to <paramref name="ifError"/> flow if response returns error
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="errorPredicate">Predicate for error to execute <paramref name="ifError"/></param>
        /// <param name="ifError">Flow to execute in case of error</param>
        /// <returns></returns>
        public static async ValueTask <ApiResponse <T> > IfError <T>(
            this ValueTask <ApiResponse <T> > source,
            TypeErrorPredicate errorPredicate,
            Func <Error, ApiResponse <T> > ifError)
        {
            var response = await source.ConfigureAwait(false);

            return(response.IfErrorRef(ref errorPredicate, ifError));
        }
コード例 #3
0
        /// <summary>
        /// Execute <paramref name="onError"/> if response has errors
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="errorPredicate">Error predicate</param>
        /// <param name="onError"></param>
        /// <returns></returns>
        public static async ValueTask <ApiResponse <T> > OnError <T>(
            this ValueTask <ApiResponse <T> > source,
            TypeErrorPredicate errorPredicate,
            Action <Error> onError
            )
        {
            var response = await source.ConfigureAwait(false);

            return(response.OnErrorRef(ref errorPredicate, onError));
        }
コード例 #4
0
        /// <summary>
        /// Switch to <paramref name="ifError"/> flow if response returns error
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="errorPredicate">Predicate for error to execute <paramref name="ifError"/></param>
        /// <param name="ifError">Flow to execute in case of error</param>
        /// <returns></returns>
        public static async Task <ApiResponse <T> > IfError <T>(
            this Task <ApiResponse <T> > source,
            TypeErrorPredicate errorPredicate,
            Func <Error, Task <ApiResponse <T> > > ifError)
        {
            var response = await source.ConfigureAwait(false);

            return(await response
                   .IfError(errorPredicate, ifError)
                   .ConfigureAwait(false));
        }
コード例 #5
0
        /// <summary>
        /// Return ok response and suppress errors that match <paramref name="errorPredicate"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="errorPredicate">Predicate for errors</param>
        /// <returns></returns>
        public static ApiResponse <Unit> SuppressErrors <T>(
            this ApiResponse <T> source,
            TypeErrorPredicate errorPredicate)
        {
            if (source.Error is not null && errorPredicate.IsMatch(source.Error))
            {
                return(ApiResponse.Ok());
            }

            return(source.AsUnit());
        }
コード例 #6
0
        /// <summary>
        /// Switch to <paramref name="ifError"/> flow if response returns error
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="errorPredicate">Predicate for error to execute <paramref name="ifError"/></param>
        /// <param name="ifError">Flow to execute in case of error</param>
        /// <returns></returns>
        public static ApiResponse <T> IfError <T>(
            this ApiResponse <T> source,
            TypeErrorPredicate errorPredicate,
            Func <Error, ApiResponse <T> > ifError)
        {
            if (source.Error is not null && errorPredicate.IsMatch(source.Error))
            {
                return(ifError(source.Error));
            }

            return(source);
        }
コード例 #7
0
        /// <summary>
        /// Execute <paramref name="onError"/> if response has errors
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="errorPredicate">Error predicate</param>
        /// <param name="onError"></param>
        /// <returns></returns>
        public static async ValueTask <ApiResponse <T> > OnError <T>(
            this ValueTask <ApiResponse <T> > source,
            TypeErrorPredicate errorPredicate,
            Func <Error, ValueTask> onError
            )
        {
            var response = await source.ConfigureAwait(false);

            return(await response
                   .OnError(errorPredicate, onError)
                   .ConfigureAwait(false));
        }
コード例 #8
0
        /// <summary>
        /// Switch to <paramref name="ifError"/> flow if response returns error
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="errorPredicate">Predicate for error to execute <paramref name="ifError"/></param>
        /// <param name="ifError">Flow to execute in case of error</param>
        /// <returns></returns>
        public static async Task <ApiResponse <T> > IfError <T>(
            this ApiResponse <T> source,
            TypeErrorPredicate errorPredicate,
            Func <Error, Task <ApiResponse <T> > > ifError)
        {
            if (source.Error is not null && errorPredicate.IsMatch(source.Error))
            {
                return(await ifError(source.Error).ConfigureAwait(false));
            }

            return(source);
        }
        /// <summary>
        /// Return ok response and suppress errors that match <paramref name="errorPredicate"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="errorPredicate">Predicate for errors</param>
        /// <returns></returns>
        public static async ValueTask <ApiResponse <Unit> > SuppressErrors <T>(
            this ValueTask <ApiResponse <T> > source,
            TypeErrorPredicate errorPredicate)
        {
            var response = await source.ConfigureAwait(false);

            if (response.Error is not null && errorPredicate.IsMatch(response.Error))
            {
                return(ApiResponse.Ok());
            }

            return(response.AsUnit());
        }
        /// <summary>
        /// Execute <paramref name="onError"/> if response has errors
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="errorPredicate">Error predicate</param>
        /// <param name="onError"></param>
        /// <returns></returns>
        public static async ValueTask <ApiResponse <T> > OnError <T>(
            this ApiResponse <T> source,
            TypeErrorPredicate errorPredicate,
            Func <Error, ValueTask> onError
            )
        {
            if (source.Error is not null && errorPredicate.IsMatch(source.Error))
            {
                await onError(source.Error).ConfigureAwait(false);
            }

            return(source);
        }
コード例 #11
0
        /// <summary>
        /// Execute <paramref name="onError"/> if response has errors
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="errorPredicate">Error predicate</param>
        /// <param name="onError"></param>
        /// <returns></returns>
        public static ApiResponse <T> OnError <T>(
            this ApiResponse <T> source,
            TypeErrorPredicate errorPredicate,
            Action <Error> onError
            )
        {
            if (source.Error is not null && errorPredicate.IsMatch(source.Error))
            {
                onError(source.Error);
            }

            return(source);
        }