@@ -259,7 +259,7 @@ public IEnumerable<PSKeyVaultCertificateContact> GetCertificateContacts(string v
259
259
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
260
260
return null ;
261
261
else
262
- throw ;
262
+ throw GetInnerException ( ex ) ;
263
263
}
264
264
catch ( Exception ex )
265
265
{
@@ -302,7 +302,7 @@ public PSKeyVaultCertificate GetCertificate(string vaultName, string certName, s
302
302
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
303
303
return null ;
304
304
else
305
- throw ;
305
+ throw GetInnerException ( ex ) ;
306
306
}
307
307
catch ( Exception ex )
308
308
{
@@ -331,7 +331,7 @@ public PSKeyVaultKey GetKey(string vaultName, string keyName, string keyVersion)
331
331
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
332
332
return null ;
333
333
else
334
- throw ;
334
+ throw GetInnerException ( ex ) ;
335
335
}
336
336
catch ( Exception ex )
337
337
{
@@ -602,7 +602,7 @@ public PSKeyVaultSecret GetSecret(string vaultName, string secretName, string se
602
602
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
603
603
return null ;
604
604
else
605
- throw ;
605
+ throw GetInnerException ( ex ) ;
606
606
}
607
607
catch ( Exception ex )
608
608
{
@@ -777,7 +777,7 @@ public PSKeyVaultCertificateOperation GetCertificateOperation(string vaultName,
777
777
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
778
778
return null ;
779
779
else
780
- throw ;
780
+ throw GetInnerException ( ex ) ;
781
781
}
782
782
catch ( Exception ex )
783
783
{
@@ -974,7 +974,7 @@ public PSKeyVaultCertificatePolicy GetCertificatePolicy(string vaultName, string
974
974
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
975
975
return null ;
976
976
else
977
- throw ;
977
+ throw GetInnerException ( ex ) ;
978
978
}
979
979
catch ( Exception ex )
980
980
{
@@ -1027,7 +1027,7 @@ public PSKeyVaultCertificateIssuer GetCertificateIssuer(string vaultName, string
1027
1027
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
1028
1028
return null ;
1029
1029
else
1030
- throw ;
1030
+ throw GetInnerException ( ex ) ;
1031
1031
}
1032
1032
catch ( Exception ex )
1033
1033
{
@@ -1439,6 +1439,13 @@ public PSDeletedKeyVaultManagedStorageSasDefinition DeleteManagedStorageSasDefin
1439
1439
private Exception GetInnerException ( Exception exception )
1440
1440
{
1441
1441
while ( exception . InnerException != null ) exception = exception . InnerException ;
1442
+ if ( exception is KeyVaultErrorException kvEx && kvEx ? . Body ? . Error != null )
1443
+ {
1444
+ var detailedMsg = exception . Message ;
1445
+ detailedMsg += string . Format ( Environment . NewLine + "Code: {0}" , kvEx . Body . Error . Code ) ;
1446
+ detailedMsg += string . Format ( Environment . NewLine + "Message: {0}" , kvEx . Body . Error . Message ) ;
1447
+ exception = new KeyVaultErrorException ( detailedMsg , kvEx ) ;
1448
+ }
1442
1449
return exception ;
1443
1450
}
1444
1451
@@ -1461,7 +1468,7 @@ public PSDeletedKeyVaultKey GetDeletedKey(string vaultName, string keyName)
1461
1468
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
1462
1469
return null ;
1463
1470
else
1464
- throw ;
1471
+ throw GetInnerException ( ex ) ;
1465
1472
}
1466
1473
catch ( Exception ex )
1467
1474
{
@@ -1519,7 +1526,7 @@ public PSDeletedKeyVaultSecret GetDeletedSecret(string vaultName, string secretN
1519
1526
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
1520
1527
return null ;
1521
1528
else
1522
- throw ;
1529
+ throw GetInnerException ( ex ) ;
1523
1530
}
1524
1531
catch ( Exception ex )
1525
1532
{
@@ -1658,7 +1665,7 @@ public PSDeletedKeyVaultCertificate GetDeletedCertificate(string vaultName, stri
1658
1665
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
1659
1666
return null ;
1660
1667
else
1661
- throw ;
1668
+ throw GetInnerException ( ex ) ;
1662
1669
}
1663
1670
catch ( Exception ex )
1664
1671
{
@@ -1787,7 +1794,7 @@ public PSDeletedKeyVaultManagedStorageAccount GetDeletedManagedStorageAccount(st
1787
1794
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
1788
1795
return null ;
1789
1796
else
1790
- throw ;
1797
+ throw GetInnerException ( ex ) ;
1791
1798
}
1792
1799
catch ( Exception ex )
1793
1800
{
@@ -1818,7 +1825,7 @@ public PSDeletedKeyVaultManagedStorageSasDefinition GetDeletedManagedStorageSasD
1818
1825
if ( ex . Response . StatusCode == HttpStatusCode . NotFound )
1819
1826
return null ;
1820
1827
else
1821
- throw ;
1828
+ throw GetInnerException ( ex ) ;
1822
1829
}
1823
1830
catch ( Exception ex )
1824
1831
{
0 commit comments