Skip to content

Commit 5b62dff

Browse files
committed
Add exception messages
1 parent 446c4b0 commit 5b62dff

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

projects/RabbitMQ.Client/Exceptions/PublishException.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ public class PublishException : RabbitMQClientException
4242
private bool _isReturn = false;
4343
private ulong _publishSequenceNumber = ulong.MinValue;
4444

45-
public PublishException(ulong publishSequenceNumber, bool isReturn) : base()
45+
public PublishException(ulong publishSequenceNumber, bool isReturn) : this(publishSequenceNumber, isReturn, "Message rejected by broker.")
46+
{
47+
}
48+
49+
public PublishException(ulong publishSequenceNumber, bool isReturn, string message) : base(message)
4650
{
4751
if (publishSequenceNumber == ulong.MinValue)
4852
{
@@ -76,10 +80,10 @@ public class PublishReturnException : PublishException
7680
private readonly ushort _replyCode;
7781
private readonly string _replyText;
7882

79-
public PublishReturnException(ulong publishSequenceNumber,
83+
public PublishReturnException(ulong publishSequenceNumber, string message,
8084
string? exchange = null, string? routingKey = null,
8185
ushort? replyCode = null, string? replyText = null)
82-
: base(publishSequenceNumber, true)
86+
: base(publishSequenceNumber, true, message)
8387
{
8488
_exchange = exchange ?? string.Empty;
8589
_routingKey = routingKey ?? string.Empty;
@@ -116,7 +120,8 @@ internal static PublishException Create(bool isReturn,
116120
{
117121
if (isReturn)
118122
{
119-
return new PublishReturnException(deliveryTag, exchange, routingKey, replyCode, replyText);
123+
string message = $"{replyCode} {replyText} Exchange: {exchange} Routing Key: {routingKey}";
124+
return new PublishReturnException(deliveryTag, message, exchange, routingKey, replyCode, replyText);
120125
}
121126
else
122127
{
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
RabbitMQ.Client.Exceptions.PublishException.PublishException(ulong publishSequenceNumber, bool isReturn, string! message) -> void
12
RabbitMQ.Client.Exceptions.PublishReturnException
23
RabbitMQ.Client.Exceptions.PublishReturnException.Exchange.get -> string!
3-
RabbitMQ.Client.Exceptions.PublishReturnException.PublishReturnException(ulong publishSequenceNumber, string? exchange = null, string? routingKey = null, ushort? replyCode = null, string? replyText = null) -> void
4+
RabbitMQ.Client.Exceptions.PublishReturnException.PublishReturnException(ulong publishSequenceNumber, string! message, string? exchange = null, string? routingKey = null, ushort? replyCode = null, string? replyText = null) -> void
45
RabbitMQ.Client.Exceptions.PublishReturnException.ReplyCode.get -> ushort
56
RabbitMQ.Client.Exceptions.PublishReturnException.ReplyText.get -> string!
67
RabbitMQ.Client.Exceptions.PublishReturnException.RoutingKey.get -> string!

0 commit comments

Comments
 (0)