Skip to content

Commit

Permalink
Clarified error message when updating purged secret
Browse files Browse the repository at this point in the history
  • Loading branch information
BethanyZhou committed Apr 25, 2021
1 parent 5a79ab3 commit a3014bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/KeyVault/KeyVault/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 15 additions & 0 deletions src/KeyVault/KeyVault/Models/KeyVaultDataServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit a3014bc

Please sign in to comment.