Skip to content

Commit

Permalink
Throw NullRef exception if no client
Browse files Browse the repository at this point in the history
  • Loading branch information
raman-m committed Oct 2, 2023
1 parent 679c4ff commit ef754e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Ocelot.Provider.Eureka/Eureka.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace Ocelot.Provider.Eureka
{
public class Eureka : IServiceDiscoveryProvider
{
private readonly IDiscoveryClient _client;
private readonly string _serviceName;
private readonly IDiscoveryClient _client;

public Eureka(string serviceName, IDiscoveryClient client)
{
_client = client;
_serviceName = serviceName;
_serviceName = serviceName ?? throw new ArgumentNullException(nameof(serviceName));
_client = client ?? throw new ArgumentNullException(nameof(client));
}

public Task<List<Service>> GetAsync()
Expand Down
6 changes: 5 additions & 1 deletion src/Ocelot.Provider.Eureka/EurekaProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ public static class EurekaProviderFactory
private static IServiceDiscoveryProvider CreateProvider(IServiceProvider provider, ServiceProviderConfiguration config, DownstreamRoute route)
{
var client = provider.GetService<IDiscoveryClient>();
if (client == null)
{
throw new NullReferenceException($"Cannot get an {nameof(IDiscoveryClient)} service during {nameof(CreateProvider)} operation to instanciate the {nameof(Eureka)} provider!");
}

return Eureka.Equals(config.Type, StringComparison.OrdinalIgnoreCase) && client != null
return Eureka.Equals(config.Type, StringComparison.OrdinalIgnoreCase)
? new Eureka(route.ServiceName, client)
: null;
}
Expand Down

0 comments on commit ef754e1

Please sign in to comment.