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:
@@ -1,6 +1,8 @@
|
|||||||
using DigitalData.Core.Abstraction.Application.Repository;
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
|
using ReC.Application.Common.Exceptions;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace ReC.Application.Common.Procedures;
|
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))
|
else if (long.TryParse(guidParam.Value.ToString(), out var guid))
|
||||||
return guid;
|
return guid;
|
||||||
|
|
||||||
return 0;
|
throw new InsertObjectFailedException(
|
||||||
|
$"InsertObject stored procedure did not return a valid identifier." +
|
||||||
|
$"{JsonSerializer.Serialize(request, options: new() { WriteIndented = true })}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user