Introduce UniqueKeyConstraintViolationException
Refactor DataProcessingException to remove unique key logic and create a dedicated UniqueKeyConstraintViolationException. Update DbExceptionTransformer to use the new exception for unique key violations, improving code clarity and separation of concerns.
This commit is contained in:
parent
8a417ca765
commit
302292255c
|
|
@ -20,8 +20,9 @@ public class DbExceptionTransformer : IDbExceptionHandler<AlterationsElsaDbConte
|
|||
/// Transforms database exceptions encountered when using a postgreSQL database into more generic exceptions.
|
||||
public void Handle(DbUpdateException exception)
|
||||
{
|
||||
var ex = exception.InnerException as PostgresException;
|
||||
if (exception.InnerException is PostgresException { SqlState: "23505" })
|
||||
throw new UniqueKeyConstraintViolationException("Unable to save data", exception);
|
||||
|
||||
throw new DataProcessingException(ex?.SqlState == "23505", "Unable to save data", exception);
|
||||
throw new DataProcessingException("Unable to save data", exception);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,4 @@
|
|||
namespace Elsa.Workflows.Exceptions;
|
||||
|
||||
/// An exception that occurs during data processing.
|
||||
public class DataProcessingException(bool isUkViolation, string message, Exception exception) : Exception(message, exception)
|
||||
{
|
||||
/// Gets a value indicating whether the exception is a Unique Key violation.
|
||||
public bool IsUkViolation { get; } = isUkViolation;
|
||||
}
|
||||
public class DataProcessingException(string message, Exception exception) : Exception(message, exception);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
namespace Elsa.Workflows.Exceptions;
|
||||
|
||||
/// An exception that when a unique key constraint has been violated.
|
||||
public class UniqueKeyConstraintViolationException(string message, Exception exception) : Exception(message, exception);
|
||||
Loading…
Reference in a new issue