From 8d92373c880e361a6c99b05727f83e483cf360de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bispo?= Date: Mon, 7 Nov 2022 13:41:02 +0000 Subject: [PATCH] [SG-806] add try catch on initAsync (#2173) --- src/App/Pages/Accounts/LoginPageViewModel.cs | 29 ++++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/App/Pages/Accounts/LoginPageViewModel.cs b/src/App/Pages/Accounts/LoginPageViewModel.cs index 9377daae5..9bf0ebe2a 100644 --- a/src/App/Pages/Accounts/LoginPageViewModel.cs +++ b/src/App/Pages/Accounts/LoginPageViewModel.cs @@ -130,14 +130,21 @@ namespace Bit.App.Pages public async Task InitAsync() { - await _deviceActionService.ShowLoadingAsync(AppResources.Loading); - if (string.IsNullOrWhiteSpace(Email)) + try { - Email = await _stateService.GetRememberedEmailAsync(); + await _deviceActionService.ShowLoadingAsync(AppResources.Loading); + if (string.IsNullOrWhiteSpace(Email)) + { + Email = await _stateService.GetRememberedEmailAsync(); + } + var deviceIdentifier = await _appIdService.GetAppIdAsync(); + IsKnownDevice = await _apiService.GetKnownDeviceAsync(Email, deviceIdentifier); + await _deviceActionService.HideLoadingAsync(); + } + catch (Exception ex) + { + HandleException(ex); } - var deviceIdentifier = await _appIdService.GetAppIdAsync(); - IsKnownDevice = await _apiService.GetKnownDeviceAsync(Email, deviceIdentifier); - await _deviceActionService.HideLoadingAsync(); } public async Task LogInAsync(bool showLoading = true, bool checkForExistingAccount = false) @@ -298,5 +305,15 @@ namespace Bit.App.Pages _messagingService.Send("switchedAccount"); } } + + private void HandleException(Exception ex) + { + Xamarin.Essentials.MainThread.InvokeOnMainThreadAsync(async () => + { + await _deviceActionService.HideLoadingAsync(); + await _platformUtilsService.ShowDialogAsync(AppResources.GenericErrorMessage); + }).FireAndForget(); + _logger.Exception(ex); + } } }