Files
ReC/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionViewsCommand.cs
TekH dbe09cd07b 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.
2026-03-24 16:00:47 +01:00

44 lines
1.4 KiB
C#

using DigitalData.Core.Abstractions.Interfaces;
using MediatR;
using ReC.Application.RecActions.Queries;
using ReC.Domain.Constants;
namespace ReC.Application.RecActions.Commands;
public record InvokeBatchRecActionViewsCommand : IRequest
{
public long ProfileId { get; init; }
}
public static class InvokeBatchRecActionViewsCommandExtensions
{
public static Task InvokeBatchRecActionView(this ISender sender, long profileId, CancellationToken cancel = default)
=> sender.Send(new InvokeBatchRecActionViewsCommand { ProfileId = profileId }, cancel);
}
public class InvokeRecActionViewsCommandHandler(ISender sender) : IRequestHandler<InvokeBatchRecActionViewsCommand>
{
public async Task Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel)
{
var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId }, cancel);
foreach (var action in actions)
{
try
{
await sender.Send(new InvokeRecActionViewCommand() { Action = action }, cancel);
}
catch
{
switch (action.ErrorAction)
{
case ErrorAction.Continue:
break;
default:
// Rethrow the exception to stop processing further actions
throw;
}
}
}
}
}