Add logging to handle null RestType in RecActionCommand
Enhanced the `InvokeRecActionCommandHandler` class by adding logging functionality using `ILogger`. Updated the constructor to accept an optional logger parameter. Introduced a check for `RestType` being `null` and added a warning log to handle such cases gracefully. This prevents processing invalid actions and improves system robustness.
This commit is contained in:
parent
73ee0302ef
commit
dcc0e8c806
@ -1,4 +1,5 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReC.Application.RecActions.Queries;
|
||||
|
||||
namespace ReC.Application.RecActions.Commands;
|
||||
@ -13,7 +14,7 @@ public static class InvokeRecActionCommandExtensions
|
||||
=> sender.Send(new InvokeRecActionCommand { ProfileId = profileId });
|
||||
}
|
||||
|
||||
public class InvokeRecActionCommandHandler(ISender sender, IHttpClientFactory clientFactory) : IRequestHandler<InvokeRecActionCommand>
|
||||
public class InvokeRecActionCommandHandler(ISender sender, IHttpClientFactory clientFactory, ILogger<InvokeRecActionCommandHandler>? logger = null) : IRequestHandler<InvokeRecActionCommand>
|
||||
{
|
||||
public async Task Handle(InvokeRecActionCommand request, CancellationToken cancel)
|
||||
{
|
||||
@ -28,6 +29,16 @@ public class InvokeRecActionCommandHandler(ISender sender, IHttpClientFactory cl
|
||||
await semaphore.WaitAsync(cancel);
|
||||
try
|
||||
{
|
||||
if (action.RestType is null)
|
||||
{
|
||||
logger?.LogWarning(
|
||||
"Rec action could not be invoked because the RestType value is null. ProfileId: {ProfileId}, ActionId: {ActionId}",
|
||||
action.ProfileId,
|
||||
action.ActionId
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
var method = new HttpMethod(action.RestType.ToUpper());
|
||||
var msg = new HttpRequestMessage(method, action.EndpointUri);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user