Skip to content

Commit

Permalink
Introduce UniqueKeyConstraintViolationException
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
raymonddenhaan committed Aug 20, 2024
1 parent 8a417ca commit 3022922
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 3022922

Please sign in to comment.