Skip to content

Commit 5f9916f

Browse files
authored
Displayed error code and message when updating purged secret (Azure#14822)
Co-authored-by: Beisi Zhou <[email protected]>
1 parent f17baf7 commit 5f9916f

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/KeyVault/KeyVault/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Displayed error code and message when updating purged secret [#14800]
2122

2223
## Version 3.4.2
2324
* Fixed a bug for `Get-AzKeyVaultSecret -AsPlainText` if the secret is not found [#14645]

src/KeyVault/KeyVault/Models/KeyVaultDataServiceClient.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public IEnumerable<PSKeyVaultCertificateContact> GetCertificateContacts(string v
259259
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
260260
return null;
261261
else
262-
throw;
262+
throw GetInnerException(ex);
263263
}
264264
catch (Exception ex)
265265
{
@@ -302,7 +302,7 @@ public PSKeyVaultCertificate GetCertificate(string vaultName, string certName, s
302302
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
303303
return null;
304304
else
305-
throw;
305+
throw GetInnerException(ex);
306306
}
307307
catch (Exception ex)
308308
{
@@ -331,7 +331,7 @@ public PSKeyVaultKey GetKey(string vaultName, string keyName, string keyVersion)
331331
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
332332
return null;
333333
else
334-
throw;
334+
throw GetInnerException(ex);
335335
}
336336
catch (Exception ex)
337337
{
@@ -602,7 +602,7 @@ public PSKeyVaultSecret GetSecret(string vaultName, string secretName, string se
602602
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
603603
return null;
604604
else
605-
throw;
605+
throw GetInnerException(ex);
606606
}
607607
catch (Exception ex)
608608
{
@@ -777,7 +777,7 @@ public PSKeyVaultCertificateOperation GetCertificateOperation(string vaultName,
777777
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
778778
return null;
779779
else
780-
throw;
780+
throw GetInnerException(ex);
781781
}
782782
catch (Exception ex)
783783
{
@@ -974,7 +974,7 @@ public PSKeyVaultCertificatePolicy GetCertificatePolicy(string vaultName, string
974974
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
975975
return null;
976976
else
977-
throw;
977+
throw GetInnerException(ex);
978978
}
979979
catch (Exception ex)
980980
{
@@ -1027,7 +1027,7 @@ public PSKeyVaultCertificateIssuer GetCertificateIssuer(string vaultName, string
10271027
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
10281028
return null;
10291029
else
1030-
throw;
1030+
throw GetInnerException(ex);
10311031
}
10321032
catch (Exception ex)
10331033
{
@@ -1439,6 +1439,13 @@ public PSDeletedKeyVaultManagedStorageSasDefinition DeleteManagedStorageSasDefin
14391439
private Exception GetInnerException(Exception exception)
14401440
{
14411441
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+
}
14421449
return exception;
14431450
}
14441451

@@ -1461,7 +1468,7 @@ public PSDeletedKeyVaultKey GetDeletedKey(string vaultName, string keyName)
14611468
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
14621469
return null;
14631470
else
1464-
throw;
1471+
throw GetInnerException(ex);
14651472
}
14661473
catch (Exception ex)
14671474
{
@@ -1519,7 +1526,7 @@ public PSDeletedKeyVaultSecret GetDeletedSecret(string vaultName, string secretN
15191526
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
15201527
return null;
15211528
else
1522-
throw;
1529+
throw GetInnerException(ex);
15231530
}
15241531
catch (Exception ex)
15251532
{
@@ -1658,7 +1665,7 @@ public PSDeletedKeyVaultCertificate GetDeletedCertificate(string vaultName, stri
16581665
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
16591666
return null;
16601667
else
1661-
throw;
1668+
throw GetInnerException(ex);
16621669
}
16631670
catch (Exception ex)
16641671
{
@@ -1787,7 +1794,7 @@ public PSDeletedKeyVaultManagedStorageAccount GetDeletedManagedStorageAccount(st
17871794
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
17881795
return null;
17891796
else
1790-
throw;
1797+
throw GetInnerException(ex);
17911798
}
17921799
catch (Exception ex)
17931800
{
@@ -1818,7 +1825,7 @@ public PSDeletedKeyVaultManagedStorageSasDefinition GetDeletedManagedStorageSasD
18181825
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
18191826
return null;
18201827
else
1821-
throw;
1828+
throw GetInnerException(ex);
18221829
}
18231830
catch (Exception ex)
18241831
{

0 commit comments

Comments
 (0)