Skip to content

Commit

Permalink
Make channel selection error info more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Jul 20, 2023
1 parent dc70720 commit b677ce5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
18 changes: 18 additions & 0 deletions Bloxstrap/Exceptions/HttpResponseUnsuccessfulException.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
6 changes: 4 additions & 2 deletions Bloxstrap/RobloxDeployment.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Bloxstrap
using Bloxstrap.Exceptions;

namespace Bloxstrap
{
public static class RobloxDeployment
{
Expand Down Expand Up @@ -109,7 +111,7 @@ public static async Task<ClientVersion> GetInfo(string channel, bool extraInform
$"\tResponse: {rawResponse}"
);

throw new Exception($"Could not get latest deploy for channel {channel}! (HTTP {deployInfoResponse.StatusCode})");
throw new HttpResponseUnsuccessfulException(deployInfoResponse);
}

clientVersion = JsonSerializer.Deserialize<ClientVersion>(rawResponse)!;
Expand Down
2 changes: 1 addition & 1 deletion Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<ui:ProgressRing Grid.Column="0" Margin="6" IsIndeterminate="True" Visibility="{Binding LoadingSpinnerVisibility, Mode=OneWay}" />
<Image Grid.Column="0" Margin="6" Width="60" Height="60" Visibility="{Binding LoadingErrorVisibility, Mode=OneWay}" RenderOptions.BitmapScalingMode="HighQuality" Source="pack://application:,,,/Resources/MessageBox/Error.png" />

<TextBlock Grid.Column="1" Margin="16" VerticalAlignment="Center" Text="{Binding ChannelInfoLoadingText, Mode=OneWay}" />
<TextBlock Grid.Column="1" Margin="16" VerticalAlignment="Center" Text="{Binding ChannelInfoLoadingText, Mode=OneWay}" TextWrapping="Wrap" />
</Grid>
</StackPanel>
</ui:CardExpander>
Expand Down
25 changes: 23 additions & 2 deletions Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Windows;

using Bloxstrap.Exceptions;

namespace Bloxstrap.UI.ViewModels.Menu
{
public class BehaviourViewModel : NotifyPropertyChangedViewModel
Expand Down Expand Up @@ -39,11 +41,30 @@ private async Task LoadChannelDeployInfo(string channel)
OnPropertyChanged(nameof(ChannelWarningVisibility));
OnPropertyChanged(nameof(ChannelDeployInfo));
}
catch (Exception)
catch (HttpResponseUnsuccessfulException ex)
{
LoadingSpinnerVisibility = Visibility.Collapsed;
LoadingErrorVisibility = Visibility.Visible;

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;
ChannelInfoLoadingText = "Could not get deployment information! Is the channel name valid?";

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));
Expand Down

0 comments on commit b677ce5

Please sign in to comment.