Throw exception on failed InsertObject identifier return

Replace default return of 0 with InsertObjectFailedException when the stored procedure does not return a valid identifier. Exception message includes serialized request for easier debugging. Added necessary imports for exception and JSON serialization.
This commit is contained in:
2026-01-12 16:27:45 +01:00
parent b48ebd8e88
commit 11206cf84f

View File

@@ -1,6 +1,8 @@
using DigitalData.Core.Abstraction.Application.Repository;
using MediatR;
using Microsoft.Data.SqlClient;
using ReC.Application.Common.Exceptions;
using System.Text.Json;
namespace ReC.Application.Common.Procedures;
@@ -183,6 +185,8 @@ public class InsertObjectProcedureHandler(IRepository repo) : IRequestHandler<In
else if (long.TryParse(guidParam.Value.ToString(), out var guid))
return guid;
return 0;
throw new InsertObjectFailedException(
$"InsertObject stored procedure did not return a valid identifier." +
$"{JsonSerializer.Serialize(request, options: new() { WriteIndented = true })}");
}
}