From dbe09cd07b23cfb9d3d3b53a58795b54f28ea735 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 24 Mar 2026 16:00:47 +0100 Subject: [PATCH] Refactor error handling in RecActionView invocation Switch to exception-based error handling for invoking RecActionView actions, removing boolean return values and related checks. Update command and handler signatures to use void return type. Clean up unused using directives. This improves clarity and robustness of error management during batch processing. --- .../Commands/InvokeBatchRecActionViewsCommand.cs | 12 +++++++++--- .../Commands/InvokeRecActionViewCommand.cs | 10 +++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionViewsCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionViewsCommand.cs index e8f1f48..d689a1e 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionViewsCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionViewsCommand.cs @@ -24,15 +24,21 @@ public class InvokeRecActionViewsCommandHandler(ISender sender) : IRequestHandle foreach (var action in actions) { - var ok = await sender.Send(new InvokeRecActionViewCommand() { Action = action }, cancel); - if (!ok) + try + { + await sender.Send(new InvokeRecActionViewCommand() { Action = action }, cancel); + } + catch + { switch (action.ErrorAction) { case ErrorAction.Continue: break; default: - return; + // Rethrow the exception to stop processing further actions + throw; } + } } } } \ No newline at end of file diff --git a/src/ReC.Application/RecActions/Commands/InvokeRecActionViewCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeRecActionViewCommand.cs index 2cf7b89..d4b6aa8 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeRecActionViewCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeRecActionViewCommand.cs @@ -1,12 +1,10 @@ using MediatR; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; -using ReC.Application.Common; using ReC.Application.Common.Constants; using ReC.Application.Common.Dto; using ReC.Application.Common.Exceptions; using ReC.Application.Common.Options; -using ReC.Application.Common.Procedures.InsertProcedure; using ReC.Application.Results.Commands; using ReC.Domain.Constants; using System.Net; @@ -16,7 +14,7 @@ using System.Text.Json; namespace ReC.Application.RecActions.Commands; -public record InvokeRecActionViewCommand : IRequest +public record InvokeRecActionViewCommand : IRequest { public RecActionViewDto Action { get; set; } = null!; } @@ -26,11 +24,11 @@ public class InvokeRecActionViewCommandHandler( ISender sender, IHttpClientFactory clientFactory, IConfiguration? config = null - ) : IRequestHandler + ) : IRequestHandler { private readonly RecActionOptions _options = options.Value; - public async Task Handle(InvokeRecActionViewCommand request, CancellationToken cancel) + public async Task Handle(InvokeRecActionViewCommand request, CancellationToken cancel) { var action = request.Action; @@ -155,8 +153,6 @@ public class InvokeRecActionViewCommandHandler( Header = JsonSerializer.Serialize(resHeaders, options: new() { WriteIndented = false }), Body = resBody }, cancel); - - return response.IsSuccessStatusCode; } finally {