Skip to content

Commit 05a0634

Browse files
moved evaluation of pageable response to try catch block
1 parent ec08d59 commit 05a0634

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

AzureKeyVault/AzureClient.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,26 @@ public virtual async Task<IEnumerable<CurrentInventoryItem>> GetCertificatesAsyn
278278
{
279279
List<CurrentInventoryItem> inventoryItems = new List<CurrentInventoryItem>();
280280
AsyncPageable<CertificateProperties> inventory = null;
281+
var fullInventoryList = new List<CertificateProperties>();
282+
var failedCount = 0;
283+
Exception innerException = null;
284+
281285
try
282286
{
283287
logger.LogTrace("calling GetPropertiesOfCertificates() on the Certificate Client");
284288
inventory = CertClient.GetPropertiesOfCertificatesAsync();
289+
290+
logger.LogTrace($"created pageable request");
291+
292+
logger.LogTrace("iterating over result pages for complete list..");
293+
294+
await foreach (var cert in inventory)
295+
{
296+
logger.LogTrace($"adding cert with ID: {cert.Id} to the list.");
297+
fullInventoryList.Add(cert); // convert to list from pages
298+
}
285299

286-
logger.LogTrace($"got a pageable response");
300+
logger.LogTrace($"compiled full inventory list of {fullInventoryList.Count()} certificate(s)");
287301
}
288302
catch (AuthenticationFailedException ex)
289303
{
@@ -304,20 +318,6 @@ public virtual async Task<IEnumerable<CurrentInventoryItem>> GetCertificatesAsyn
304318
throw;
305319
}
306320

307-
logger.LogTrace("iterating over result pages for complete list..");
308-
309-
var fullInventoryList = new List<CertificateProperties>();
310-
var failedCount = 0;
311-
Exception innerException = null;
312-
313-
await foreach (var cert in inventory)
314-
{
315-
logger.LogTrace($"adding cert with ID: {cert.Id} to the list.");
316-
fullInventoryList.Add(cert); // convert to list from pages
317-
}
318-
319-
logger.LogTrace($"compiled full inventory list of {fullInventoryList.Count()} certificate(s)");
320-
321321
foreach (var certificate in fullInventoryList)
322322
{
323323
logger.LogTrace($"getting details for the individual certificate with id: {certificate.Id} and name: {certificate.Name}");
@@ -339,8 +339,7 @@ public virtual async Task<IEnumerable<CurrentInventoryItem>> GetCertificatesAsyn
339339
catch (Exception ex)
340340
{
341341
failedCount++;
342-
innerException = ex;
343-
logger.LogError($"Failed to retreive details for certificate {certificate.Name}. Exception: {ex.Message}");
342+
logger.LogError($"Failed to retreive details for certificate {certificate.Name}. Exception: {LogHandler.FlattenException(ex)}");
344343
// continuing with inventory instead of throwing, in case there's an issue with a single certificate
345344
}
346345
}

0 commit comments

Comments
 (0)