Add verbosity for HTTP response exceptions

This commit is contained in:
pizzaboxer 2023-07-31 11:57:45 +01:00
parent dae1dfd824
commit 767783ae22
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
5 changed files with 26 additions and 22 deletions

View File

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

View File

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

View File

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

View File

@ -128,7 +128,7 @@ namespace Bloxstrap
$"\tResponse: {rawResponse}"
);
throw new HttpResponseUnsuccessfulException(deployInfoResponse);
throw new HttpResponseException(deployInfoResponse);
}
clientVersion = JsonSerializer.Deserialize<ClientVersion>(rawResponse)!;

View File

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