diff --git a/src/KeyVault/KeyVault/ChangeLog.md b/src/KeyVault/KeyVault/ChangeLog.md index bb0bbfc16e6b..6faa876b4b50 100644 --- a/src/KeyVault/KeyVault/ChangeLog.md +++ b/src/KeyVault/KeyVault/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Upcoming Release +* Clarified error 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..0b09eeda749d 100644 --- a/src/KeyVault/KeyVault/Models/KeyVaultDataServiceClient.cs +++ b/src/KeyVault/KeyVault/Models/KeyVaultDataServiceClient.cs @@ -20,6 +20,7 @@ using System.Net; using System.Security; using System.Security.Cryptography.X509Certificates; +using System.Text.RegularExpressions; using System.Xml; using Microsoft.Azure.Commands.Common.Authentication; using Microsoft.Azure.Commands.Common.Authentication.Abstractions; @@ -1439,6 +1440,20 @@ public PSDeletedKeyVaultManagedStorageSasDefinition DeleteManagedStorageSasDefin private Exception GetInnerException(Exception exception) { while (exception.InnerException != null) exception = exception.InnerException; + if (exception is KeyVaultErrorException kvEx) + { + var detailedMsg = exception.Message; + var match = Regex.Match(kvEx.Response.Content, @"""message"":"".+?"""); + while (match.Success) + { + var msg = match.Value.Substring(11); + msg = msg.Substring(0, msg.Length - 1); + detailedMsg += (Environment.NewLine + msg); + match = match.NextMatch(); + } + + exception = new KeyVaultErrorException(detailedMsg, kvEx); + } return exception; }