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)
|
foreach (var action in actions)
|
||||||
{
|
{
|
||||||
var ok = await sender.Send(new InvokeRecActionViewCommand() { Action = action }, cancel);
|
try
|
||||||
if (!ok)
|
{
|
||||||
|
await sender.Send(new InvokeRecActionViewCommand() { Action = action }, cancel);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
switch (action.ErrorAction)
|
switch (action.ErrorAction)
|
||||||
{
|
{
|
||||||
case ErrorAction.Continue:
|
case ErrorAction.Continue:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
// Rethrow the exception to stop processing further actions
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using ReC.Application.Common;
|
|
||||||
using ReC.Application.Common.Constants;
|
using ReC.Application.Common.Constants;
|
||||||
using ReC.Application.Common.Dto;
|
using ReC.Application.Common.Dto;
|
||||||
using ReC.Application.Common.Exceptions;
|
using ReC.Application.Common.Exceptions;
|
||||||
using ReC.Application.Common.Options;
|
using ReC.Application.Common.Options;
|
||||||
using ReC.Application.Common.Procedures.InsertProcedure;
|
|
||||||
using ReC.Application.Results.Commands;
|
using ReC.Application.Results.Commands;
|
||||||
using ReC.Domain.Constants;
|
using ReC.Domain.Constants;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@@ -16,7 +14,7 @@ using System.Text.Json;
|
|||||||
|
|
||||||
namespace ReC.Application.RecActions.Commands;
|
namespace ReC.Application.RecActions.Commands;
|
||||||
|
|
||||||
public record InvokeRecActionViewCommand : IRequest<bool>
|
public record InvokeRecActionViewCommand : IRequest
|
||||||
{
|
{
|
||||||
public RecActionViewDto Action { get; set; } = null!;
|
public RecActionViewDto Action { get; set; } = null!;
|
||||||
}
|
}
|
||||||
@@ -26,11 +24,11 @@ public class InvokeRecActionViewCommandHandler(
|
|||||||
ISender sender,
|
ISender sender,
|
||||||
IHttpClientFactory clientFactory,
|
IHttpClientFactory clientFactory,
|
||||||
IConfiguration? config = null
|
IConfiguration? config = null
|
||||||
) : IRequestHandler<InvokeRecActionViewCommand, bool>
|
) : IRequestHandler<InvokeRecActionViewCommand>
|
||||||
{
|
{
|
||||||
private readonly RecActionOptions _options = options.Value;
|
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;
|
var action = request.Action;
|
||||||
|
|
||||||
@@ -155,8 +153,6 @@ public class InvokeRecActionViewCommandHandler(
|
|||||||
Header = JsonSerializer.Serialize(resHeaders, options: new() { WriteIndented = false }),
|
Header = JsonSerializer.Serialize(resHeaders, options: new() { WriteIndented = false }),
|
||||||
Body = resBody
|
Body = resBody
|
||||||
}, cancel);
|
}, cancel);
|
||||||
|
|
||||||
return response.IsSuccessStatusCode;
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user