Skip to content

Commit c6075a4

Browse files
committed
Added different exception types
1 parent 0fead41 commit c6075a4

File tree

7 files changed

+46
-4
lines changed

7 files changed

+46
-4
lines changed

src/Billing/SimulationEffects.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Billing;
22

3+
using Helper;
34
using MassTransit;
45
using Messages;
56
using Microsoft.AspNetCore.SignalR;
@@ -29,7 +30,7 @@ public async Task SimulateBillingProcessing(ConsumeContext<OrderPlaced> context)
2930
&& (!isRetry || ShouldFailRetries))
3031
{
3132
Interlocked.Increment(ref messagesErrored);
32-
throw new Exception($"A simulated failure occurred in Billing, OrderId: {context.Message.OrderId}, Contents: {string.Join(", ", context.Message.Contents)}");
33+
throw new BillingProcessingException($"A simulated failure occurred in Billing, OrderId: {context.Message.OrderId}, Contents: {string.Join(", ", context.Message.Contents)}");
3334
}
3435

3536
Interlocked.Increment(ref messagesProcessed);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Helper
2+
{
3+
using System;
4+
5+
public class BillingProcessingException : Exception
6+
{
7+
public BillingProcessingException(string message) : base(message)
8+
{
9+
}
10+
}
11+
}

src/Helper/OrderBilledException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Helper
2+
{
3+
public class OrderBilledException : Exception
4+
{
5+
public OrderBilledException(string message) : base(message)
6+
{
7+
}
8+
}
9+
}

src/Helper/OrderPlacedException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Helper
2+
{
3+
public class OrderPlacedException : Exception
4+
{
5+
public OrderPlacedException(string message) : base(message)
6+
{
7+
}
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Helper
2+
{
3+
4+
public class SalesProcessingException : Exception
5+
{
6+
public SalesProcessingException(string message) : base(message)
7+
{
8+
}
9+
}
10+
}

src/Sales/SimulationEffects.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Sales;
22

3+
using Helper;
34
using MassTransit;
45
using Messages;
56
using Microsoft.AspNetCore.SignalR;
@@ -29,7 +30,7 @@ public async Task SimulateSalesProcessing(ConsumeContext<PlaceOrder> context)
2930
&& (!isRetry || ShouldFailRetries))
3031
{
3132
Interlocked.Increment(ref messagesErrored);
32-
throw new Exception($"A simulated failure occurred in Sales, OrderId: {context.Message.OrderId}, Contents: {string.Join(", ", context.Message.Contents)}");
33+
throw new SalesProcessingException($"A simulated failure occurred in Sales, OrderId: {context.Message.OrderId}, Contents: {string.Join(", ", context.Message.Contents)}");
3334
}
3435

3536
Interlocked.Increment(ref messagesProcessed);

src/Shipping/SimulationEffects.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Shipping;
22

3+
using Helper;
34
using MassTransit;
45
using Messages;
56
using Microsoft.AspNetCore.SignalR;
@@ -33,7 +34,7 @@ public async Task SimulateOrderBilledProcessing(ConsumeContext<OrderBilled> cont
3334
&& (!isRetry || ShouldFailRetries))
3435
{
3536
Interlocked.Increment(ref orderBilledErrored);
36-
throw new Exception($"A simulated failure occurred in Shipping Order Billed handling, OrderId: {context.Message.OrderId}, Contents: {string.Join(", ", context.Message.Contents)}");
37+
throw new OrderBilledException($"A simulated failure occurred in Shipping Order Billed handling, OrderId: {context.Message.OrderId}, Contents: {string.Join(", ", context.Message.Contents)}");
3738
}
3839

3940
Interlocked.Increment(ref orderBilledProcessed);
@@ -59,7 +60,7 @@ public async Task SimulateOrderPlacedProcessing(ConsumeContext<OrderPlaced> cont
5960
&& (!isRetry || ShouldFailRetries))
6061
{
6162
Interlocked.Increment(ref orderPlacedErrored);
62-
throw new Exception($"A simulated failure occurred in Shipping Order Placed handling, OrderId: {context.Message.OrderId}, Contents: {string.Join(", ", context.Message.Contents)}");
63+
throw new OrderPlacedException($"A simulated failure occurred in Shipping Order Placed handling, OrderId: {context.Message.OrderId}, Contents: {string.Join(", ", context.Message.Contents)}");
6364
}
6465

6566
Interlocked.Increment(ref orderPlacedProcessed);

0 commit comments

Comments
 (0)