Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display error message when updating purged secret #14822

Merged
merged 1 commit into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
* 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]
Expand Down
31 changes: 19 additions & 12 deletions src/KeyVault/KeyVault/Models/KeyVaultDataServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public IEnumerable<PSKeyVaultCertificateContact> GetCertificateContacts(string v
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
return null;
else
throw;
throw GetInnerException(ex);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -1787,7 +1794,7 @@ public PSDeletedKeyVaultManagedStorageAccount GetDeletedManagedStorageAccount(st
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
return null;
else
throw;
throw GetInnerException(ex);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1818,7 +1825,7 @@ public PSDeletedKeyVaultManagedStorageSasDefinition GetDeletedManagedStorageSasD
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
return null;
else
throw;
throw GetInnerException(ex);
}
catch (Exception ex)
{
Expand Down