From f9998f23e8bc1f2d258c996711672a35a1f93675 Mon Sep 17 00:00:00 2001 From: Arthur Thomas Date: Wed, 31 Jul 2024 23:50:40 -0400 Subject: [PATCH] fix: add more error handling --- .../ViewModels/PropertiesPageViewModel.cs | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/KeyVaultExplorer/ViewModels/PropertiesPageViewModel.cs b/KeyVaultExplorer/ViewModels/PropertiesPageViewModel.cs index 39a8819..8cb4176 100644 --- a/KeyVaultExplorer/ViewModels/PropertiesPageViewModel.cs +++ b/KeyVaultExplorer/ViewModels/PropertiesPageViewModel.cs @@ -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) { @@ -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() @@ -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) { @@ -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 }; @@ -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" }); } } } \ No newline at end of file