Skip to content

Commit bacdb7a

Browse files
authored
Add try catch block to address issue #56 (#57)
* Add try catch block to fix issue #56 * Add space for formatting * Add try catch block to fix issue #56
1 parent 973bd4b commit bacdb7a

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

Source/VaultSharp.Extensions.Configuration/VaultChangeWatcher.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public VaultChangeWatcher(IConfiguration configuration, ILogger? logger = null)
3232
}
3333

3434
this._logger = logger;
35-
35+
3636
this._configProviders = configurationRoot.Providers.OfType<VaultConfigurationProvider>().Where(p => p.ConfigurationSource.Options.ReloadOnChange).ToList() !;
3737
}
3838

@@ -54,26 +54,34 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
5454

5555
while (!stoppingToken.IsCancellationRequested)
5656
{
57-
await Task.Delay(TimeSpan.FromSeconds(minTime), stoppingToken).ConfigureAwait(false);
58-
if (stoppingToken.IsCancellationRequested)
59-
{
60-
break;
61-
}
62-
63-
for (var j = 0; j < this._configProviders.Count(); j++)
57+
try
6458
{
65-
var timer = timers[j];
66-
timer -= minTime;
67-
if (timer <= 0)
59+
await Task.Delay(TimeSpan.FromSeconds(minTime), stoppingToken).ConfigureAwait(false);
60+
if (stoppingToken.IsCancellationRequested)
6861
{
69-
this._configProviders.ElementAt(j).Load();
70-
timers[j] = this._configProviders.ElementAt(j).ConfigurationSource.Options.ReloadCheckIntervalSeconds;
62+
break;
7163
}
72-
else
64+
65+
for (var j = 0; j < this._configProviders.Count(); j++)
7366
{
74-
timers[j] = timer;
67+
var timer = timers[j];
68+
timer -= minTime;
69+
if (timer <= 0)
70+
{
71+
this._configProviders.ElementAt(j).Load();
72+
timers[j] = this._configProviders.ElementAt(j).ConfigurationSource.Options
73+
.ReloadCheckIntervalSeconds;
74+
}
75+
else
76+
{
77+
timers[j] = timer;
78+
}
7579
}
7680
}
81+
catch (Exception ex)
82+
{
83+
this._logger?.LogError(ex, $"An exception occurred in {nameof(VaultChangeWatcher)}");
84+
}
7785
}
7886
}
7987
}

0 commit comments

Comments
 (0)