Skip to content

Commit

Permalink
Add custom message to ConcurrencyException (#568)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Alhayek <[email protected]>
  • Loading branch information
hyzx86 and MikeAlhayek authored Jun 6, 2024
1 parent e2b1e32 commit 01fea28
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/YesSql.Abstractions/ConcurrencyException.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System;
using System.Reflection.Metadata;

namespace YesSql
{
public class ConcurrencyException : Exception
{
public ConcurrencyException() : base("The document could not be updated as it has been changed by another process.")
public Document Document { get; }

public ConcurrencyException(Document document) : base($"The document with Id '{document.Id}' and type '{document.Type}' could not be updated as it has been changed by another process.")
{
Document = document;
}
}
}
2 changes: 1 addition & 1 deletion src/YesSql.Core/Commands/UpdateDocumentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override async Task ExecuteAsync(DbConnection connection, DbTransaction t

if (_checkVersion > -1 && updatedCount != 1)
{
throw new ConcurrencyException();
throw new ConcurrencyException(Document);
}

return;
Expand Down

0 comments on commit 01fea28

Please sign in to comment.