Skip to content

Commit

Permalink
Merge pull request #67 from LBHackney-IT/feature/error-handling-ddb-f…
Browse files Browse the repository at this point in the history
…ixture

Ignore ConditionalCheckFailedException during entity deletion in DynamoDbFixture
  • Loading branch information
notatiyyah authored Feb 4, 2025
2 parents 49ec337 + 2d09609 commit fc38e54
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,18 @@ public void EnsureTablesExist(List<TableDef> tables)
public async Task SaveEntityAsync<T>(T entity) where T : class
{
await DynamoDbContext.SaveAsync<T>(entity).ConfigureAwait(false);
_cleanup.Add(async () => await DynamoDbContext.DeleteAsync(entity).ConfigureAwait(false));
_cleanup.Add(async () =>
{
try
{
await DynamoDbContext.DeleteAsync(entity).ConfigureAwait(false);
}
catch (ConditionalCheckFailedException ex)
{
// Ignore this exception as it means the entity has already been deleted
Console.WriteLine($"Delete failed: {ex.Message}");
}
});
}
}
}

0 comments on commit fc38e54

Please sign in to comment.