Skip to content

Commit

Permalink
Displayed error code and message when updating purged secret (#14822)
Browse files Browse the repository at this point in the history
Co-authored-by: Beisi Zhou <bez@microsoft.com>
  • Loading branch information
BethanyZhou and BethanyZhou authored Apr 25, 2021
1 parent f17baf7 commit 5f9916f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 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
* 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

0 comments on commit 5f9916f

Please sign in to comment.