[SG-806] add try catch on initAsync (#2173)

This commit is contained in:
André Bispo 2022-11-07 13:41:02 +00:00 committed by GitHub
parent 6bfc8f7d49
commit 8d92373c88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 6 deletions

View File

@ -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);
}
}
}