Skip to content

Commit a271bff

Browse files
committed
Merge branch 'main' into release/2.6
2 parents 3136661 + 0288134 commit a271bff

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/NATS.Client.Core/Commands/CommandWriter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public ValueTask PublishAsync<T>(string subject, T? value, NatsHeaders? headers,
323323
var size = payloadBuffer.WrittenMemory.Length + (headersBuffer?.WrittenMemory.Length ?? 0);
324324
if (_connection.ServerInfo is { } info && size > info.MaxPayload)
325325
{
326-
throw new NatsException($"Payload size {size} exceeds server's maximum payload size {info.MaxPayload}");
326+
throw new NatsPayloadTooLargeException($"Payload size {size} exceeds server's maximum payload size {info.MaxPayload}");
327327
}
328328
}
329329
catch

src/NATS.Client.Core/NatsException.cs

+8
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,11 @@ public NatsServerException(string error)
5050

5151
public bool IsAuthError { get; }
5252
}
53+
54+
public sealed class NatsPayloadTooLargeException : NatsException
55+
{
56+
public NatsPayloadTooLargeException(string error)
57+
: base(error)
58+
{
59+
}
60+
}

tests/NATS.Client.Core2.Tests/ProtocolTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ await Retry.Until(
443443

444444
{
445445
var payload = new byte[nats.ServerInfo!.MaxPayload + 1];
446-
var exception = await Assert.ThrowsAsync<NatsException>(async () =>
446+
var exception = await Assert.ThrowsAsync<NatsPayloadTooLargeException>(async () =>
447447
await nats.PublishAsync("foo.none", payload, cancellationToken: cts.Token));
448448
Assert.Matches(@"Payload size \d+ exceeds server's maximum payload size \d+", exception.Message);
449449
}

0 commit comments

Comments
 (0)