From 6068a4bd565ef0ddbebef91430b6b76324d809ae Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 30 Jul 2016 18:16:09 -0400 Subject: [PATCH] Handle unexpected error cases on API calls better. --- .../Pages/Settings/SettingsAddFolderPage.cs | 4 ++++ .../Pages/Settings/SettingsEditFolderPage.cs | 12 ++++++++++++ src/App/Pages/Vault/VaultAddSitePage.cs | 4 ++++ src/App/Pages/Vault/VaultEditSitePage.cs | 12 ++++++++++++ src/iOS.Extension/SiteAddViewController.cs | 19 +++++++++++++++---- 5 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/App/Pages/Settings/SettingsAddFolderPage.cs b/src/App/Pages/Settings/SettingsAddFolderPage.cs index d55a12f1c..ebdd0bb22 100644 --- a/src/App/Pages/Settings/SettingsAddFolderPage.cs +++ b/src/App/Pages/Settings/SettingsAddFolderPage.cs @@ -84,6 +84,10 @@ namespace Bit.App.Pages { await _userDialogs.AlertAsync(saveTask.Result.Errors.First().Message, AppResources.AnErrorHasOccurred); } + else + { + await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred); + } }, ToolbarItemOrder.Default, 0); Title = "Add Folder"; diff --git a/src/App/Pages/Settings/SettingsEditFolderPage.cs b/src/App/Pages/Settings/SettingsEditFolderPage.cs index fa4557dc4..4f8c77ca9 100644 --- a/src/App/Pages/Settings/SettingsEditFolderPage.cs +++ b/src/App/Pages/Settings/SettingsEditFolderPage.cs @@ -98,6 +98,10 @@ namespace Bit.App.Pages { await _userDialogs.AlertAsync(saveTask.Result.Errors.First().Message, AppResources.AnErrorHasOccurred); } + else + { + await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred); + } }, ToolbarItemOrder.Default, 0); Title = "Edit Folder"; @@ -143,6 +147,14 @@ namespace Bit.App.Pages await Navigation.PopModalAsync(); _userDialogs.Toast("Folder deleted."); } + else if((await deleteTask).Errors.Count() > 0) + { + await _userDialogs.AlertAsync((await deleteTask).Errors.First().Message, AppResources.AnErrorHasOccurred); + } + else + { + await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred); + } } private void AlertNoConnection() diff --git a/src/App/Pages/Vault/VaultAddSitePage.cs b/src/App/Pages/Vault/VaultAddSitePage.cs index 9c7d94c11..9a7f89bff 100644 --- a/src/App/Pages/Vault/VaultAddSitePage.cs +++ b/src/App/Pages/Vault/VaultAddSitePage.cs @@ -144,6 +144,10 @@ namespace Bit.App.Pages { await _userDialogs.AlertAsync(saveTask.Result.Errors.First().Message, AppResources.AnErrorHasOccurred); } + else + { + await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred); + } }, ToolbarItemOrder.Default, 0); Title = AppResources.AddSite; diff --git a/src/App/Pages/Vault/VaultEditSitePage.cs b/src/App/Pages/Vault/VaultEditSitePage.cs index b3fabbc69..a13dfb6cc 100644 --- a/src/App/Pages/Vault/VaultEditSitePage.cs +++ b/src/App/Pages/Vault/VaultEditSitePage.cs @@ -179,6 +179,10 @@ namespace Bit.App.Pages { await _userDialogs.AlertAsync(saveTask.Result.Errors.First().Message, AppResources.AnErrorHasOccurred); } + else + { + await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred); + } }, ToolbarItemOrder.Default, 0); Title = "Edit Site"; @@ -238,6 +242,14 @@ namespace Bit.App.Pages await Navigation.PopModalAsync(); _userDialogs.Toast("Site deleted."); } + else if((await deleteTask).Errors.Count() > 0) + { + await _userDialogs.AlertAsync((await deleteTask).Errors.First().Message, AppResources.AnErrorHasOccurred); + } + else + { + await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred); + } } private void AlertNoConnection() diff --git a/src/iOS.Extension/SiteAddViewController.cs b/src/iOS.Extension/SiteAddViewController.cs index 3d994da71..15d545756 100644 --- a/src/iOS.Extension/SiteAddViewController.cs +++ b/src/iOS.Extension/SiteAddViewController.cs @@ -161,13 +161,24 @@ namespace Bit.iOS.Extension PresentViewController(loadingAlert, true, null); await saveTask; - if(SiteListController != null) + if(saveTask.Result.Succeeded) { - SiteListController.DismissModal(); + if(SiteListController != null) + { + SiteListController.DismissModal(); + } + else if(LoadingController != null) + { + LoadingController.CompleteUsernamePasswordRequest(UsernameCell.TextField.Text, PasswordCell.TextField.Text); + } } - else if(LoadingController != null) + else if(saveTask.Result.Errors.Count() > 0) { - LoadingController.CompleteUsernamePasswordRequest(UsernameCell.TextField.Text, PasswordCell.TextField.Text); + DisplayAlert(AppResources.AnErrorHasOccurred, saveTask.Result.Errors.First().Message, AppResources.Ok); + } + else + { + DisplayAlert(null, AppResources.AnErrorHasOccurred, AppResources.Ok); } }