From e62dfbcc7a7351ef6f9976273fe8654b109a81a0 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 1 Dec 2025 12:51:54 +0100 Subject: [PATCH] Improve error handling with DataIntegrityException Introduce a new `DataIntegrityException` class to handle data integrity issues. Replace the logging and early return for `null` `RestType` in `InvokeRecActionCommandHandler` with throwing the new exception. This ensures explicit error handling and improves runtime issue detection. --- .../Common/Exceptions/DataIntegrityException.cs | 8 ++++++++ .../RecActions/Commands/InvokeRecActionCommand.cs | 14 ++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 src/ReC.Application/Common/Exceptions/DataIntegrityException.cs diff --git a/src/ReC.Application/Common/Exceptions/DataIntegrityException.cs b/src/ReC.Application/Common/Exceptions/DataIntegrityException.cs new file mode 100644 index 0000000..f354500 --- /dev/null +++ b/src/ReC.Application/Common/Exceptions/DataIntegrityException.cs @@ -0,0 +1,8 @@ +namespace ReC.Application.Common.Exceptions; + +public class DataIntegrityException : Exception +{ + public DataIntegrityException() { } + + public DataIntegrityException(string message) : base(message) { } +} \ No newline at end of file diff --git a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs index 418848e..75655d8 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using ReC.Application.Common; using ReC.Application.Common.Dto; +using ReC.Application.Common.Exceptions; using ReC.Application.OutResults.Commands; using System.Text.Json; @@ -31,14 +32,11 @@ public class InvokeRecActionCommandHandler( using var http = clientFactory.CreateClient(); if (action.RestType is null) - { - logger?.LogWarning( - "Rec action could not be invoked because the RestType value is null. ProfileId: {ProfileId}, Id: {Id}", - action.ProfileId, - action.Id - ); - return; - } + throw new DataIntegrityException( + $"Rec action could not be invoked because the RestType value is null. " + + $"ProfileId: {action.ProfileId}, " + + $"Id: {action.Id}" + ); using var httpReq = action.RestType .ToHttpMethod()