Skip to content

Commit 996c5af

Browse files
Merge pull request #743 from TransactionProcessing/task/#725_merchant_domain)event_hander_retry
add error message based on result properties
2 parents ba7b95f + 975b5df commit 996c5af

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

TransactionProcessor.BusinessLogic/Common/PolicyFactory.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
using EventStore.Client;
1+
using EventStore.Client;
42
using Grpc.Core;
53
using Polly;
64
using Polly.Fallback;
75
using Polly.Retry;
86
using Polly.Wrap;
97
using Shared.Logger;
108
using SimpleResults;
9+
using System;
10+
using System.Linq;
11+
using System.Threading.Tasks;
1112

1213
namespace TransactionProcessor.BusinessLogic.Common;
1314

@@ -29,10 +30,17 @@ public static async Task<Result> ExecuteWithPolicyAsync(Func<Task<Result>> actio
2930
{
3031
var context = new Context();
3132
context["RetryCount"] = 0;
32-
//Result result = await policy.ExecuteAsync(action);
33+
3334
Result result = await policy.ExecuteAsync((ctx) => action(), context);
35+
3436
int retryCount = (int)context["RetryCount"];
35-
String message = result.IsSuccess ? "Execution succeeded." : $"Execution failed with error: {result.Message}";
37+
String message = result switch
38+
{
39+
{ IsSuccess: true } => "Success",
40+
{ IsSuccess: false, Message: not "" } => result.Message,
41+
{ IsSuccess: false, Message: "", Errors: var errors } when errors.Any() => string.Join(", ", errors),
42+
_ => "Unknown Error"
43+
};
3644
String retryMessage = retryCount > 0 ? $" after {retryCount} retries." : "";
3745
// Log success if no retries were required
3846

0 commit comments

Comments
 (0)