From b677ce5aead21189e915ad02eed6c16055fd3b56 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Thu, 20 Jul 2023 12:39:03 +0100 Subject: [PATCH] Make channel selection error info more accurate --- .../HttpResponseUnsuccessfulException.cs | 18 +++++++++++++ Bloxstrap/RobloxDeployment.cs | 6 +++-- .../UI/Elements/Menu/Pages/BehaviourPage.xaml | 2 +- .../UI/ViewModels/Menu/BehaviourViewModel.cs | 25 +++++++++++++++++-- 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 Bloxstrap/Exceptions/HttpResponseUnsuccessfulException.cs diff --git a/Bloxstrap/Exceptions/HttpResponseUnsuccessfulException.cs b/Bloxstrap/Exceptions/HttpResponseUnsuccessfulException.cs new file mode 100644 index 0000000..1409f78 --- /dev/null +++ b/Bloxstrap/Exceptions/HttpResponseUnsuccessfulException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bloxstrap.Exceptions +{ + internal class HttpResponseUnsuccessfulException : Exception + { + public HttpResponseMessage ResponseMessage { get; } + + public HttpResponseUnsuccessfulException(HttpResponseMessage responseMessage) : base() + { + ResponseMessage = responseMessage; + } + } +} diff --git a/Bloxstrap/RobloxDeployment.cs b/Bloxstrap/RobloxDeployment.cs index 067e732..c44ccf3 100644 --- a/Bloxstrap/RobloxDeployment.cs +++ b/Bloxstrap/RobloxDeployment.cs @@ -1,4 +1,6 @@ -namespace Bloxstrap +using Bloxstrap.Exceptions; + +namespace Bloxstrap { public static class RobloxDeployment { @@ -109,7 +111,7 @@ $"\tResponse: {rawResponse}" ); - throw new Exception($"Could not get latest deploy for channel {channel}! (HTTP {deployInfoResponse.StatusCode})"); + throw new HttpResponseUnsuccessfulException(deployInfoResponse); } clientVersion = JsonSerializer.Deserialize(rawResponse)!; diff --git a/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml b/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml index f137e8f..c18bfb8 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml +++ b/Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml @@ -100,7 +100,7 @@ - + diff --git a/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs index 8b7e4f7..3895f37 100644 --- a/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs @@ -1,5 +1,7 @@ using System.Windows; +using Bloxstrap.Exceptions; + namespace Bloxstrap.UI.ViewModels.Menu { public class BehaviourViewModel : NotifyPropertyChangedViewModel @@ -39,11 +41,30 @@ namespace Bloxstrap.UI.ViewModels.Menu OnPropertyChanged(nameof(ChannelWarningVisibility)); OnPropertyChanged(nameof(ChannelDeployInfo)); } - catch (Exception) + catch (HttpResponseUnsuccessfulException ex) { LoadingSpinnerVisibility = Visibility.Collapsed; LoadingErrorVisibility = Visibility.Visible; - ChannelInfoLoadingText = "Could not get deployment information! Is the channel name valid?"; + + ChannelInfoLoadingText = ex.ResponseMessage.StatusCode switch + { + HttpStatusCode.NotFound => "The specified channel name does not exist.", + _ => $"Failed to fetch information! (HTTP {ex.ResponseMessage.StatusCode})", + }; + + OnPropertyChanged(nameof(LoadingSpinnerVisibility)); + OnPropertyChanged(nameof(LoadingErrorVisibility)); + OnPropertyChanged(nameof(ChannelInfoLoadingText)); + } + catch (Exception ex) + { + LoadingSpinnerVisibility = Visibility.Collapsed; + LoadingErrorVisibility = Visibility.Visible; + + App.Logger.WriteLine("[BehaviourViewModel::LoadChannelDeployInfo] An exception occurred while fetching channel information"); + App.Logger.WriteLine($"[BehaviourViewModel::LoadChannelDeployInfo] {ex}"); + + ChannelInfoLoadingText = $"Failed to fetch information! ({ex.Message})"; OnPropertyChanged(nameof(LoadingSpinnerVisibility)); OnPropertyChanged(nameof(LoadingErrorVisibility));