From dcc0e8c806809180e1c62e58024f1f4247c65d5b Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Wed, 26 Nov 2025 21:54:22 +0100 Subject: [PATCH] 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. --- .../RecActions/Commands/InvokeRecActionCommand.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs index e8ae005..f7d95da 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs @@ -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 +public class InvokeRecActionCommandHandler(ISender sender, IHttpClientFactory clientFactory, ILogger? logger = null) : IRequestHandler { 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);