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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<bool>
|
||||
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<InvokeRecActionViewCommand, bool>
|
||||
) : IRequestHandler<InvokeRecActionViewCommand>
|
||||
{
|
||||
private readonly RecActionOptions _options = options.Value;
|
||||
|
||||
public async Task<bool> 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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user