From 767783ae22e577c9e9ddabd604992e55996861ed Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Mon, 31 Jul 2023 11:57:45 +0100 Subject: [PATCH] Add verbosity for HTTP response exceptions --- Bloxstrap/App.xaml.cs | 5 ++++- Bloxstrap/Exceptions/HttpResponseException.cs | 19 +++++++++++++++++++ .../HttpResponseUnsuccessfulException.cs | 18 ------------------ Bloxstrap/RobloxDeployment.cs | 2 +- .../UI/ViewModels/Menu/BehaviourViewModel.cs | 4 ++-- 5 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 Bloxstrap/Exceptions/HttpResponseException.cs delete mode 100644 Bloxstrap/Exceptions/HttpResponseUnsuccessfulException.cs diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index c2c7441..1d85017 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -162,11 +162,14 @@ namespace Bloxstrap Logger.WriteLine(LOG_IDENT, "Connectivity check failed!"); Logger.WriteException(LOG_IDENT, ex); + if (ex.GetType() == typeof(AggregateException)) + ex = ex.InnerException!; + Controls.ShowMessageBox( "Bloxstrap is unable to connect to the internet. Please check your network configuration and try again.\n" + "\n" + "More information:\n" + - ex.InnerException!.Message, + ex.Message, MessageBoxImage.Error, MessageBoxButton.OK ); diff --git a/Bloxstrap/Exceptions/HttpResponseException.cs b/Bloxstrap/Exceptions/HttpResponseException.cs new file mode 100644 index 0000000..08404b0 --- /dev/null +++ b/Bloxstrap/Exceptions/HttpResponseException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bloxstrap.Exceptions +{ + internal class HttpResponseException : Exception + { + public HttpResponseMessage ResponseMessage { get; } + + public HttpResponseException(HttpResponseMessage responseMessage) + : base($"Could not connect to {responseMessage.RequestMessage!.RequestUri} because it returned HTTP {(int)responseMessage.StatusCode} ({responseMessage.ReasonPhrase})") + { + ResponseMessage = responseMessage; + } + } +} diff --git a/Bloxstrap/Exceptions/HttpResponseUnsuccessfulException.cs b/Bloxstrap/Exceptions/HttpResponseUnsuccessfulException.cs deleted file mode 100644 index 1409f78..0000000 --- a/Bloxstrap/Exceptions/HttpResponseUnsuccessfulException.cs +++ /dev/null @@ -1,18 +0,0 @@ -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 3fe148c..70efe89 100644 --- a/Bloxstrap/RobloxDeployment.cs +++ b/Bloxstrap/RobloxDeployment.cs @@ -128,7 +128,7 @@ namespace Bloxstrap $"\tResponse: {rawResponse}" ); - throw new HttpResponseUnsuccessfulException(deployInfoResponse); + throw new HttpResponseException(deployInfoResponse); } clientVersion = JsonSerializer.Deserialize(rawResponse)!; diff --git a/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs index ef4c5bb..79bb4cc 100644 --- a/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs @@ -40,7 +40,7 @@ namespace Bloxstrap.UI.ViewModels.Menu OnPropertyChanged(nameof(ChannelDeployInfo)); } - catch (HttpResponseUnsuccessfulException ex) + catch (HttpResponseException ex) { ShowLoadingError = true; OnPropertyChanged(nameof(ShowLoadingError)); @@ -48,7 +48,7 @@ namespace Bloxstrap.UI.ViewModels.Menu ChannelInfoLoadingText = ex.ResponseMessage.StatusCode switch { HttpStatusCode.NotFound => "The specified channel name does not exist.", - _ => $"Failed to fetch information! (HTTP {ex.ResponseMessage.StatusCode})", + _ => $"Failed to fetch information! (HTTP {(int)ex.ResponseMessage.StatusCode} - {ex.ResponseMessage.ReasonPhrase})", }; OnPropertyChanged(nameof(ChannelInfoLoadingText)); }