Skip to content

Commit

Permalink
fix: add more error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cricketthomas committed Aug 1, 2024
1 parent 17d028c commit f9998f2
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions KeyVaultExplorer/ViewModels/PropertiesPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,10 @@ private async Task EditVersion()
viewModel.IsEdit = true;
dialog.PrimaryButtonClick += async (sender, args) =>
{
var def = args.GetDeferral();
try
{
var def = args.GetDeferral();
await viewModel.EditDetailsCommand.ExecuteAsync(null);
def.Complete();
}
catch (KeyVaultInsufficientPrivilegesException ex)
{
Expand All @@ -225,6 +224,10 @@ private async Task EditVersion()
{
_notificationViewModel.ShowErrorPopup(new Avalonia.Controls.Notifications.Notification { Message = ex.Message, Title = "Error" });
}
finally
{
def.Complete();
}
};

dialog.Content = new CreateNewSecretVersion()
Expand Down Expand Up @@ -311,11 +314,10 @@ private async Task NewVersion()

dialog.PrimaryButtonClick += async (sender, args) =>
{
var def = args.GetDeferral();
try
{
var def = args.GetDeferral();
await viewModel.NewVersionCommand.ExecuteAsync(null);
def.Complete();
}
catch (KeyVaultInsufficientPrivilegesException ex)
{
Expand All @@ -325,6 +327,10 @@ private async Task NewVersion()
{
_notificationViewModel.ShowErrorPopup(new Avalonia.Controls.Notifications.Notification { Message = ex.Message, Title = "Error" });
}
finally
{
def.Complete();
}
};

dialog.Content = new CreateNewSecretVersion() { DataContext = viewModel };
Expand Down Expand Up @@ -372,10 +378,24 @@ private async void SaveFile(string fileName, string ext, string content)
[RelayCommand]
private async Task ShouldShowValue(bool val)
{
if (IsSecret && val && IsEnabled)
try
{
if (IsSecret && val && IsEnabled)
{
await Dispatcher.UIThread.InvokeAsync(async () =>
{
var s = await _vaultService.GetSecret(kvUri: OpenedItem.SecretProperties.VaultUri, secretName: OpenedItem.SecretProperties.Name).ConfigureAwait(false);
SecretPlainText = s.Value;
});
}
}
catch (KeyVaultInsufficientPrivilegesException ex)
{
var s = await _vaultService.GetSecret(kvUri: OpenedItem.SecretProperties.VaultUri, secretName: OpenedItem.SecretProperties.Name).ConfigureAwait(false);
SecretPlainText = s.Value;
_notificationViewModel.ShowErrorPopup(new Avalonia.Controls.Notifications.Notification { Message = ex.Message, Title = "Insufficient Rights" });
}
catch (Exception ex)
{
_notificationViewModel.ShowErrorPopup(new Avalonia.Controls.Notifications.Notification { Message = ex.Message, Title = "Error" });
}
}
}

0 comments on commit f9998f2

Please sign in to comment.