Ejemplo n.º 1
0
        protected async Task <Response <TResult> > HandleWithErrorsAsync <TResult>(TRequest request,
                                                                                   IServiceProvider provider,
                                                                                   CancellationToken token,
                                                                                   Func <TRequest, IServiceProvider, CancellationToken, Task <TResult> > handleAsync)
        {
            var result = default(TResult);

            try
            {
                token.ThrowIfCancellationRequested();

                try
                {
                    result = await handleAsync(request, provider, token).Configure();
                }
                catch (AggregateException e)
                {
                    throw Unwrap(e);
                }
            }
            catch (Exception e) when(FailedToFindError.IsReturnedFor(e))
            {
                return(ErrorDispatcher.Dispatch <TResult>(FailedToFindError.From(request, e)));
            }
            catch (Exception e) when(RequestFailedError.IsReturnedFor(e))
            {
                return(ErrorDispatcher.Dispatch <TResult>(RequestFailedError.From(request, e)));
            }
            catch (Exception e) when(RequestCanceledError.IsReturnedFor(e))
            {
                return(ErrorDispatcher.Dispatch <TResult>(RequestCanceledError.From(request, e)));
            }
            catch (Exception e) when(HookFailedError.IsReturnedFor(e))
            {
                return(ErrorDispatcher.Dispatch <TResult>(HookFailedError.From(request, e)));
            }
            catch (Exception e) when(CreateEntityFailedError.IsReturnedFor(e))
            {
                return(ErrorDispatcher.Dispatch <TResult>(CreateEntityFailedError.From(request, e)));
            }
            catch (Exception e) when(UpdateEntityFailedError.IsReturnedFor(e))
            {
                return(ErrorDispatcher.Dispatch <TResult>(UpdateEntityFailedError.From(request, e)));
            }
            catch (Exception e) when(CreateResultFailedError.IsReturnedFor(e))
            {
                return(ErrorDispatcher.Dispatch <TResult>(CreateResultFailedError.From(request, e)));
            }

            return(result.AsResponse());
        }
Ejemplo n.º 2
0
        protected async Task <Response <TResult> > HandleWithErrorsAsync <TResult>(TRequest request, Func <TRequest, CancellationToken, Task <TResult> > handleAsync)
        {
            var result = default(TResult);

            using (var cts = new CancellationTokenSource())
            {
                try
                {
                    result = await handleAsync(request, cts.Token).Configure();
                }
                catch (Exception e) when(FailedToFindError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch <TResult>(FailedToFindError.From(request, e)));
                }
                catch (Exception e) when(RequestFailedError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch <TResult>(RequestFailedError.From(request, e)));
                }
                catch (Exception e) when(RequestCanceledError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch <TResult>(RequestCanceledError.From(request, e)));
                }
                catch (Exception e) when(HookFailedError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch <TResult>(HookFailedError.From(request, e)));
                }
                catch (Exception e) when(CreateEntityFailedError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch <TResult>(CreateEntityFailedError.From(request, e)));
                }
                catch (Exception e) when(UpdateEntityFailedError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch <TResult>(UpdateEntityFailedError.From(request, e)));
                }
                catch (Exception e) when(CreateResultFailedError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch <TResult>(CreateResultFailedError.From(request, e)));
                }
            }

            return(result.AsResponse());
        }
Ejemplo n.º 3
0
        protected async Task <Response> HandleWithErrorsAsync(TRequest request, Func <TRequest, CancellationToken, Task> handleAsync)
        {
            using (var cts = new CancellationTokenSource())
            {
                try
                {
                    await handleAsync(request, cts.Token).Configure();
                }
                catch (Exception e) when(FailedToFindError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch(FailedToFindError.From(request, e)));
                }
                catch (Exception e) when(RequestFailedError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch(RequestFailedError.From(request, e)));
                }
                catch (Exception e) when(RequestCanceledError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch(RequestCanceledError.From(request, e)));
                }
                catch (Exception e) when(HookFailedError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch(HookFailedError.From(request, e)));
                }
                catch (Exception e) when(CreateEntityFailedError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch(CreateEntityFailedError.From(request, e)));
                }
                catch (Exception e) when(UpdateEntityFailedError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch(UpdateEntityFailedError.From(request, e)));
                }
                catch (Exception e) when(CreateResultFailedError.IsReturnedFor(e))
                {
                    return(ErrorDispatcher.Dispatch(CreateResultFailedError.From(request, e)));
                }
            }

            return(Response.Success());
        }
 protected override Response HandleError(RequestCanceledError error) => throw new Exception(error.Exception?.Message, error.Exception);
 protected override Response HandleError(RequestCanceledError error)
 => GenericHandle(error);