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.
This commit is contained in:
tekh 2025-12-01 12:51:54 +01:00
parent a2ebbe83cb
commit e62dfbcc7a
2 changed files with 14 additions and 8 deletions

View File

@ -0,0 +1,8 @@
namespace ReC.Application.Common.Exceptions;
public class DataIntegrityException : Exception
{
public DataIntegrityException() { }
public DataIntegrityException(string message) : base(message) { }
}

View File

@ -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
throw new DataIntegrityException(
$"Rec action could not be invoked because the RestType value is null. " +
$"ProfileId: {action.ProfileId}, " +
$"Id: {action.Id}"
);
return;
}
using var httpReq = action.RestType
.ToHttpMethod()