Skip to content

Commit 81b4128

Browse files
committed
PR review
1 parent 15f7d65 commit 81b4128

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

projects/RabbitMQ.Client/client/api/IEndpointResolverExtensions.cs

+11-10
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static async Task<T> SelectOneAsync<T>(this IEndpointResolver resolver,
4242
Func<AmqpTcpEndpoint, CancellationToken, Task<T>> selector, CancellationToken cancellationToken)
4343
{
4444
var t = default(T);
45-
List<Exception> exceptions = null;
45+
List<Exception> exceptions = [];
4646
foreach (AmqpTcpEndpoint ep in resolver.All())
4747
{
4848
try
@@ -53,23 +53,24 @@ public static async Task<T> SelectOneAsync<T>(this IEndpointResolver resolver,
5353
return t;
5454
}
5555
}
56-
// TODO immediate re-throw vs trying the next host?
57-
catch (TaskCanceledException)
56+
catch (OperationCanceledException ex)
5857
{
59-
throw;
60-
}
61-
catch (AggregateException)
62-
{
63-
throw;
58+
if (cancellationToken.IsCancellationRequested)
59+
{
60+
throw;
61+
}
62+
else
63+
{
64+
exceptions.Add(ex);
65+
}
6466
}
6567
catch (Exception e)
6668
{
67-
exceptions ??= new List<Exception>(1);
6869
exceptions.Add(e);
6970
}
7071
}
7172

72-
if (Object.Equals(t, default(T)) && exceptions?.Count > 0)
73+
if (Object.Equals(t, default(T)) && exceptions.Count > 0)
7374
{
7475
throw new AggregateException(exceptions);
7576
}

0 commit comments

Comments
 (0)