Refactor InsertObjectFailedException for more context

InsertObjectFailedException now requires an InsertObjectProcedure
instance, improving error context. Exception throwing in
InsertObjectProcedureHandler updated to pass the procedure object
instead of just a message and serialized request.
This commit is contained in:
2026-01-14 09:44:31 +01:00
parent 2692553865
commit 24f146ca26
2 changed files with 11 additions and 6 deletions

View File

@@ -1,16 +1,23 @@
using ReC.Application.Common.Procedures.InsertProcedure;
namespace ReC.Application.Common.Exceptions;
public class InsertObjectFailedException : Exception
{
public InsertObjectFailedException() : base()
private readonly InsertObjectProcedure _procedure;
public InsertObjectFailedException(InsertObjectProcedure procedure) : base()
{
_procedure = procedure;
}
public InsertObjectFailedException(string? message) : base(message)
public InsertObjectFailedException(InsertObjectProcedure procedure, string? message) : base(message)
{
_procedure = procedure;
}
public InsertObjectFailedException(string? message, Exception? innerException) : base(message, innerException)
public InsertObjectFailedException(InsertObjectProcedure procedure, string? message, Exception? innerException) : base(message, innerException)
{
_procedure = procedure;
}
}

View File

@@ -113,8 +113,6 @@ public class InsertObjectProcedureHandler(IRepository repo) : IRequestHandler<In
else if (long.TryParse(guidParam.Value.ToString(), out var guid))
return guid;
throw new InsertObjectFailedException(
"InsertObject stored procedure did not return a valid identifier." +
JsonSerializer.Serialize(request, options: new() { WriteIndented = true }));
throw new InsertObjectFailedException(request, "InsertObject stored procedure did not return a valid identifier.");
}
}