Skip to content

Commit 39397a6

Browse files
committed
Add exception messages
1 parent 446c4b0 commit 39397a6

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

projects/RabbitMQ.Client/Exceptions/PublishException.cs

+17-4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ public PublishException(ulong publishSequenceNumber, bool isReturn) : base()
5353
_publishSequenceNumber = publishSequenceNumber;
5454
}
5555

56+
public PublishException(ulong publishSequenceNumber, bool isReturn, string message) : base(message)
57+
{
58+
if (publishSequenceNumber == ulong.MinValue)
59+
{
60+
throw new ArgumentException($"{nameof(publishSequenceNumber)} must not be 0");
61+
}
62+
63+
_isReturn = isReturn;
64+
_publishSequenceNumber = publishSequenceNumber;
65+
}
66+
5667
/// <summary>
5768
/// <c>true</c> if this exception is due to a <c>basic.return</c>
5869
/// </summary>
@@ -76,10 +87,10 @@ public class PublishReturnException : PublishException
7687
private readonly ushort _replyCode;
7788
private readonly string _replyText;
7889

79-
public PublishReturnException(ulong publishSequenceNumber,
90+
public PublishReturnException(ulong publishSequenceNumber, string message,
8091
string? exchange = null, string? routingKey = null,
8192
ushort? replyCode = null, string? replyText = null)
82-
: base(publishSequenceNumber, true)
93+
: base(publishSequenceNumber, true, message)
8394
{
8495
_exchange = exchange ?? string.Empty;
8596
_routingKey = routingKey ?? string.Empty;
@@ -116,11 +127,13 @@ internal static PublishException Create(bool isReturn,
116127
{
117128
if (isReturn)
118129
{
119-
return new PublishReturnException(deliveryTag, exchange, routingKey, replyCode, replyText);
130+
string message = $"{replyCode} {replyText} Exchange: {exchange} Routing Key: {routingKey}";
131+
return new PublishReturnException(deliveryTag, message, exchange, routingKey, replyCode, replyText);
120132
}
121133
else
122134
{
123-
return new PublishException(deliveryTag, isReturn);
135+
string message = "Message rejected by broker.";
136+
return new PublishException(deliveryTag, isReturn, message);
124137
}
125138
}
126139
}
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)