Skip to content

Commit

Permalink
fix(grpc): fake address and error log on empty address from resolver …
Browse files Browse the repository at this point in the history
…instead of exception
  • Loading branch information
SonicGD committed Nov 29, 2023
1 parent 7d46000 commit bdf72e2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Sitko.Core.Grpc.Client/GrpcCallInvokerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class GrpcCallInvokerFactory
private readonly ConcurrentDictionary<EntryKey, IGrpcServiceAddressResolver> resolvers = new();

private readonly IServiceScopeFactory scopeFactory;
private readonly ILogger<GrpcCallInvokerFactory> logger;

public GrpcCallInvokerFactory(
IServiceScopeFactory scopeFactory,
Expand All @@ -32,6 +33,7 @@ public GrpcCallInvokerFactory(
IHttpMessageHandlerFactory messageHandlerFactory)
{
this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
this.logger = loggerFactory.CreateLogger<GrpcCallInvokerFactory>();
this.grpcClientFactoryOptionsMonitor = grpcClientFactoryOptionsMonitor;
this.httpClientFactoryOptionsMonitor = httpClientFactoryOptionsMonitor;
this.messageHandlerFactory = messageHandlerFactory;
Expand Down Expand Up @@ -100,8 +102,8 @@ private CallInvoker CreateInvoker(EntryKey key)
var address = resolver.GetAddress();
if (address == null)
{
throw new InvalidOperationException(
$@"Could not resolve the address for gRPC client '{name}'. Set an address when registering the client: services.AddGrpcClient<{type.Name}>(o => o.Address = new Uri(""https://localhost:5001""))");
logger.LogError("Could not resolve the address for gRPC client '{Name}'", name);
address = new Uri("https://localhost"); // fake address
}

var channel = GrpcChannel.ForAddress(address, channelOptions);
Expand Down

0 comments on commit bdf72e2

Please sign in to comment.