From b35498619986046f8a4d68883cea1ea2ff9956f8 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 22 Oct 2019 16:37:40 -0400 Subject: [PATCH] null check apiexception error --- src/App/Pages/Accounts/HintPageViewModel.cs | 6 +++++- src/App/Pages/Accounts/LoginPageViewModel.cs | 6 +++++- src/App/Pages/Accounts/RegisterPageViewModel.cs | 6 +++++- src/App/Pages/Accounts/TwoFactorPageViewModel.cs | 7 +++++-- src/App/Pages/Settings/FolderAddEditPageViewModel.cs | 12 ++++++++++-- src/App/Pages/Settings/SyncPageViewModel.cs | 6 +++++- src/App/Pages/Vault/AddEditPageViewModel.cs | 9 +++++++-- src/App/Pages/Vault/AttachmentsPageViewModel.cs | 12 ++++++++++-- src/App/Pages/Vault/AutofillCiphersPageViewModel.cs | 7 +++++-- src/App/Pages/Vault/CiphersPageViewModel.cs | 7 +++++-- src/App/Pages/Vault/CollectionsPageViewModel.cs | 6 +++++- src/App/Pages/Vault/SharePageViewModel.cs | 11 +++++++++-- src/App/Pages/Vault/ViewPageViewModel.cs | 6 +++++- src/iOS.Core/Controllers/LoginAddViewController.cs | 7 +++++-- 14 files changed, 86 insertions(+), 22 deletions(-) diff --git a/src/App/Pages/Accounts/HintPageViewModel.cs b/src/App/Pages/Accounts/HintPageViewModel.cs index 983b0cdcc..cb36d1ce7 100644 --- a/src/App/Pages/Accounts/HintPageViewModel.cs +++ b/src/App/Pages/Accounts/HintPageViewModel.cs @@ -60,7 +60,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } } } diff --git a/src/App/Pages/Accounts/LoginPageViewModel.cs b/src/App/Pages/Accounts/LoginPageViewModel.cs index 25e7954db..2c7fad603 100644 --- a/src/App/Pages/Accounts/LoginPageViewModel.cs +++ b/src/App/Pages/Accounts/LoginPageViewModel.cs @@ -135,7 +135,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } } diff --git a/src/App/Pages/Accounts/RegisterPageViewModel.cs b/src/App/Pages/Accounts/RegisterPageViewModel.cs index e0e712da9..2648ef976 100644 --- a/src/App/Pages/Accounts/RegisterPageViewModel.cs +++ b/src/App/Pages/Accounts/RegisterPageViewModel.cs @@ -135,7 +135,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } } diff --git a/src/App/Pages/Accounts/TwoFactorPageViewModel.cs b/src/App/Pages/Accounts/TwoFactorPageViewModel.cs index 2de247f3e..2c917b020 100644 --- a/src/App/Pages/Accounts/TwoFactorPageViewModel.cs +++ b/src/App/Pages/Accounts/TwoFactorPageViewModel.cs @@ -213,8 +213,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), - AppResources.AnErrorHasOccurred); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } } diff --git a/src/App/Pages/Settings/FolderAddEditPageViewModel.cs b/src/App/Pages/Settings/FolderAddEditPageViewModel.cs index cc65494dd..76124b962 100644 --- a/src/App/Pages/Settings/FolderAddEditPageViewModel.cs +++ b/src/App/Pages/Settings/FolderAddEditPageViewModel.cs @@ -93,7 +93,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } return false; } @@ -128,7 +132,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } return false; } diff --git a/src/App/Pages/Settings/SyncPageViewModel.cs b/src/App/Pages/Settings/SyncPageViewModel.cs index 8077a8192..ad9e75028 100644 --- a/src/App/Pages/Settings/SyncPageViewModel.cs +++ b/src/App/Pages/Settings/SyncPageViewModel.cs @@ -70,7 +70,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } } } diff --git a/src/App/Pages/Vault/AddEditPageViewModel.cs b/src/App/Pages/Vault/AddEditPageViewModel.cs index f628dad90..72a00ae76 100644 --- a/src/App/Pages/Vault/AddEditPageViewModel.cs +++ b/src/App/Pages/Vault/AddEditPageViewModel.cs @@ -458,7 +458,8 @@ namespace Bit.App.Pages await _deviceActionService.HideLoadingAsync(); if(e?.Error != null) { - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); } } return false; @@ -490,7 +491,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } return false; } diff --git a/src/App/Pages/Vault/AttachmentsPageViewModel.cs b/src/App/Pages/Vault/AttachmentsPageViewModel.cs index 6e196ed6e..afb6de84a 100644 --- a/src/App/Pages/Vault/AttachmentsPageViewModel.cs +++ b/src/App/Pages/Vault/AttachmentsPageViewModel.cs @@ -124,7 +124,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } return false; } @@ -164,7 +168,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } } diff --git a/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs b/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs index b3bd1eb33..e328500fc 100644 --- a/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs +++ b/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs @@ -157,8 +157,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), - AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } } if(autofillResponse == AppResources.Yes || autofillResponse == AppResources.YesAndSave) diff --git a/src/App/Pages/Vault/CiphersPageViewModel.cs b/src/App/Pages/Vault/CiphersPageViewModel.cs index ff0f2e4d6..fe71ab649 100644 --- a/src/App/Pages/Vault/CiphersPageViewModel.cs +++ b/src/App/Pages/Vault/CiphersPageViewModel.cs @@ -168,8 +168,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), - AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } } if(_deviceActionService.SystemMajorVersion() < 21) diff --git a/src/App/Pages/Vault/CollectionsPageViewModel.cs b/src/App/Pages/Vault/CollectionsPageViewModel.cs index 1fef161e7..fa1bf1841 100644 --- a/src/App/Pages/Vault/CollectionsPageViewModel.cs +++ b/src/App/Pages/Vault/CollectionsPageViewModel.cs @@ -85,7 +85,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } return false; } diff --git a/src/App/Pages/Vault/SharePageViewModel.cs b/src/App/Pages/Vault/SharePageViewModel.cs index 013f2d5eb..d4ed8c4a0 100644 --- a/src/App/Pages/Vault/SharePageViewModel.cs +++ b/src/App/Pages/Vault/SharePageViewModel.cs @@ -116,12 +116,19 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } catch(System.Exception e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Message, AppResources.Ok); + if(e.Message != null) + { + await _platformUtilsService.ShowDialogAsync(e.Message, AppResources.AnErrorHasOccurred); + } } return false; } diff --git a/src/App/Pages/Vault/ViewPageViewModel.cs b/src/App/Pages/Vault/ViewPageViewModel.cs index dfad94037..8e984d4c2 100644 --- a/src/App/Pages/Vault/ViewPageViewModel.cs +++ b/src/App/Pages/Vault/ViewPageViewModel.cs @@ -298,7 +298,11 @@ namespace Bit.App.Pages catch(ApiException e) { await _deviceActionService.HideLoadingAsync(); - await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } } return false; } diff --git a/src/iOS.Core/Controllers/LoginAddViewController.cs b/src/iOS.Core/Controllers/LoginAddViewController.cs index f0be3acf9..647fe74a0 100644 --- a/src/iOS.Core/Controllers/LoginAddViewController.cs +++ b/src/iOS.Core/Controllers/LoginAddViewController.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Bit.App.Resources; @@ -191,7 +191,10 @@ namespace Bit.iOS.Core.Controllers } catch(ApiException e) { - DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + if(e?.Error != null) + { + DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok); + } } }