From b4737457a879d38c23452c457a6840fe5363fd92 Mon Sep 17 00:00:00 2001 From: aj-rosado <109146700+aj-rosado@users.noreply.github.com> Date: Fri, 16 Sep 2022 18:28:20 +0100 Subject: [PATCH] PS-1404 Improved exception handling when saving an attachment (#2078) * PS-1404 Improved exception handling when saving an attachment * PS-1404 Reverted unnecessary catch change * PS-1404 Added missing whitespace * PS-1404 Improved code formatting * PS-1404 removed unnecessary whitespace * PS-1404 Using SubmitAsyncCommand on xaml and removed the click method from the cs file --- src/App/Pages/Vault/AttachmentsPage.xaml | 2 +- src/App/Pages/Vault/AttachmentsPage.xaml.cs | 8 -------- src/App/Pages/Vault/AttachmentsPageViewModel.cs | 16 +++++++++++++++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/App/Pages/Vault/AttachmentsPage.xaml b/src/App/Pages/Vault/AttachmentsPage.xaml index dd2b58605..0b56ab9c1 100644 --- a/src/App/Pages/Vault/AttachmentsPage.xaml +++ b/src/App/Pages/Vault/AttachmentsPage.xaml @@ -17,7 +17,7 @@ - + diff --git a/src/App/Pages/Vault/AttachmentsPage.xaml.cs b/src/App/Pages/Vault/AttachmentsPage.xaml.cs index 6e9391866..9e5fb6d4e 100644 --- a/src/App/Pages/Vault/AttachmentsPage.xaml.cs +++ b/src/App/Pages/Vault/AttachmentsPage.xaml.cs @@ -51,14 +51,6 @@ namespace Bit.App.Pages } } - private async void Save_Clicked(object sender, EventArgs e) - { - if (DoOnce()) - { - await _vm.SubmitAsync(); - } - } - private async void ChooseFile_Clicked(object sender, EventArgs e) { if (DoOnce()) diff --git a/src/App/Pages/Vault/AttachmentsPageViewModel.cs b/src/App/Pages/Vault/AttachmentsPageViewModel.cs index 9dc284b42..6216f5ec9 100644 --- a/src/App/Pages/Vault/AttachmentsPageViewModel.cs +++ b/src/App/Pages/Vault/AttachmentsPageViewModel.cs @@ -1,6 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using System.Windows.Input; using Bit.App.Abstractions; using Bit.App.Resources; using Bit.Core.Abstractions; @@ -8,6 +10,7 @@ using Bit.Core.Exceptions; using Bit.Core.Models.Domain; using Bit.Core.Models.View; using Bit.Core.Utilities; +using Xamarin.CommunityToolkit.ObjectModel; using Xamarin.Forms; namespace Bit.App.Pages @@ -20,6 +23,7 @@ namespace Bit.App.Pages private readonly IStateService _stateService; private readonly IVaultTimeoutService _vaultTimeoutService; private readonly IPlatformUtilsService _platformUtilsService; + private readonly ILogger _logger; private CipherView _cipher; private Cipher _cipherDomain; private bool _hasAttachments; @@ -35,8 +39,10 @@ namespace Bit.App.Pages _platformUtilsService = ServiceContainer.Resolve("platformUtilsService"); _stateService = ServiceContainer.Resolve("stateService"); _vaultTimeoutService = ServiceContainer.Resolve("vaultTimeoutService"); + _logger = ServiceContainer.Resolve(); Attachments = new ExtendedObservableCollection(); DeleteAttachmentCommand = new Command(DeleteAsync); + SubmitAsyncCommand = new AsyncCommand(SubmitAsync, allowsMultipleExecutions: false); PageTitle = AppResources.Attachments; } @@ -59,6 +65,7 @@ namespace Bit.App.Pages } public byte[] FileData { get; set; } public Command DeleteAttachmentCommand { get; set; } + public ICommand SubmitAsyncCommand { get; } public async Task InitAsync() { @@ -125,6 +132,7 @@ namespace Bit.App.Pages } catch (ApiException e) { + _logger.Exception(e); await _deviceActionService.HideLoadingAsync(); if (e?.Error != null) { @@ -132,6 +140,12 @@ namespace Bit.App.Pages AppResources.AnErrorHasOccurred); } } + catch (Exception e) + { + _logger.Exception(e); + await _deviceActionService.HideLoadingAsync(); + await _platformUtilsService.ShowDialogAsync(AppResources.GenericErrorMessage, AppResources.AnErrorHasOccurred); + } return false; }