Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebakken committed Dec 7, 2023
1 parent 15f7d65 commit 81b4128
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions projects/RabbitMQ.Client/client/api/IEndpointResolverExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static async Task<T> SelectOneAsync<T>(this IEndpointResolver resolver,
Func<AmqpTcpEndpoint, CancellationToken, Task<T>> selector, CancellationToken cancellationToken)
{
var t = default(T);
List<Exception> exceptions = null;
List<Exception> exceptions = [];
foreach (AmqpTcpEndpoint ep in resolver.All())
{
try
Expand All @@ -53,23 +53,24 @@ public static async Task<T> SelectOneAsync<T>(this IEndpointResolver resolver,
return t;
}
}
// TODO immediate re-throw vs trying the next host?
catch (TaskCanceledException)
catch (OperationCanceledException ex)
{
throw;
}
catch (AggregateException)
{
throw;
if (cancellationToken.IsCancellationRequested)
{
throw;
}
else
{
exceptions.Add(ex);
}
}
catch (Exception e)
{
exceptions ??= new List<Exception>(1);
exceptions.Add(e);
}
}

if (Object.Equals(t, default(T)) && exceptions?.Count > 0)
if (Object.Equals(t, default(T)) && exceptions.Count > 0)
{
throw new AggregateException(exceptions);
}
Expand Down

0 comments on commit 81b4128

Please sign in to comment.