From 5f9916f6ff0ab3edc0d12b81b683ced20fe58a25 Mon Sep 17 00:00:00 2001 From: Beisi Zhou Date: Sun, 25 Apr 2021 17:59:34 +0800 Subject: [PATCH] Displayed error code and message when updating purged secret (#14822) Co-authored-by: Beisi Zhou --- src/KeyVault/KeyVault/ChangeLog.md | 1 + .../Models/KeyVaultDataServiceClient.cs | 31 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/KeyVault/KeyVault/ChangeLog.md b/src/KeyVault/KeyVault/ChangeLog.md index bb0bbfc16e6b..6fa0b3ad62dd 100644 --- a/src/KeyVault/KeyVault/ChangeLog.md +++ b/src/KeyVault/KeyVault/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Upcoming Release +* Displayed error code and message when updating purged secret [#14800] ## Version 3.4.2 * Fixed a bug for `Get-AzKeyVaultSecret -AsPlainText` if the secret is not found [#14645] diff --git a/src/KeyVault/KeyVault/Models/KeyVaultDataServiceClient.cs b/src/KeyVault/KeyVault/Models/KeyVaultDataServiceClient.cs index 0f6f7b5fe801..7bfca9ef47f3 100644 --- a/src/KeyVault/KeyVault/Models/KeyVaultDataServiceClient.cs +++ b/src/KeyVault/KeyVault/Models/KeyVaultDataServiceClient.cs @@ -259,7 +259,7 @@ public IEnumerable GetCertificateContacts(string v if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) { @@ -302,7 +302,7 @@ public PSKeyVaultCertificate GetCertificate(string vaultName, string certName, s if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) { @@ -331,7 +331,7 @@ public PSKeyVaultKey GetKey(string vaultName, string keyName, string keyVersion) if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) { @@ -602,7 +602,7 @@ public PSKeyVaultSecret GetSecret(string vaultName, string secretName, string se if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) { @@ -777,7 +777,7 @@ public PSKeyVaultCertificateOperation GetCertificateOperation(string vaultName, if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) { @@ -974,7 +974,7 @@ public PSKeyVaultCertificatePolicy GetCertificatePolicy(string vaultName, string if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) { @@ -1027,7 +1027,7 @@ public PSKeyVaultCertificateIssuer GetCertificateIssuer(string vaultName, string if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) { @@ -1439,6 +1439,13 @@ public PSDeletedKeyVaultManagedStorageSasDefinition DeleteManagedStorageSasDefin private Exception GetInnerException(Exception exception) { while (exception.InnerException != null) exception = exception.InnerException; + if (exception is KeyVaultErrorException kvEx && kvEx?.Body?.Error != null) + { + var detailedMsg = exception.Message; + detailedMsg += string.Format(Environment.NewLine + "Code: {0}", kvEx.Body.Error.Code); + detailedMsg += string.Format(Environment.NewLine + "Message: {0}", kvEx.Body.Error.Message); + exception = new KeyVaultErrorException(detailedMsg, kvEx); + } return exception; } @@ -1461,7 +1468,7 @@ public PSDeletedKeyVaultKey GetDeletedKey(string vaultName, string keyName) if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) { @@ -1519,7 +1526,7 @@ public PSDeletedKeyVaultSecret GetDeletedSecret(string vaultName, string secretN if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) { @@ -1658,7 +1665,7 @@ public PSDeletedKeyVaultCertificate GetDeletedCertificate(string vaultName, stri if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) { @@ -1787,7 +1794,7 @@ public PSDeletedKeyVaultManagedStorageAccount GetDeletedManagedStorageAccount(st if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) { @@ -1818,7 +1825,7 @@ public PSDeletedKeyVaultManagedStorageSasDefinition GetDeletedManagedStorageSasD if (ex.Response.StatusCode == HttpStatusCode.NotFound) return null; else - throw; + throw GetInnerException(ex); } catch (Exception ex) {