Skip to content

Commit

Permalink
Merge pull request #5917 from elsa-workflows/enh/uk_ex
Browse files Browse the repository at this point in the history
Introduce UniqueKeyConstraintViolationException
  • Loading branch information
raymonddenhaan authored Aug 20, 2024
2 parents 8a417ca + 3022922 commit 9365bb9
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 9365bb9

Please sign in to comment.