Skip to content

Commit fa3c957

Browse files
committed
Better Error Handling in Login/Registration URL Input
1 parent eec4140 commit fa3c957

4 files changed

Lines changed: 47 additions & 12 deletions

File tree

gamevault/Models/ServerInfo.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,17 @@ public class BindableServerInfo
3434

3535
public bool IsBasicAuthEnabled { get; set; }
3636
public bool IsSSOEnabled { get; set; }
37+
public string ErrorMessage { get; set; }
38+
public bool HasError { get; set; }
3739

38-
public BindableServerInfo() { }
40+
public BindableServerInfo(string errorMessage = "")
41+
{
42+
if (errorMessage != "")
43+
{
44+
HasError = true;
45+
ErrorMessage = errorMessage;
46+
}
47+
}
3948
public BindableServerInfo(ServerInfo info)
4049
{
4150
IsAvailable = true;
@@ -46,6 +55,6 @@ public BindableServerInfo(ServerInfo info)
4655
IsBirthDateMandatory = info.RequiredRegistrationFields.Contains("birth_date");
4756
IsBasicAuthEnabled = info.AvailableAuthenticationMethods.Contains("basic");
4857
IsSSOEnabled = info.AvailableAuthenticationMethods.Contains("sso");
49-
}
58+
}
5059
}
5160
}

gamevault/Resources/Assets/Icons.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@
156156
<Geometry x:Key="IconMute">
157157
M16.775 19.575q-.275.175-.55.325t-.575.275q-.375.175-.762 0t-.538-.575q-.15-.375.038-.737t.562-.538q.175-.075.325-.162t.3-.188L12 14.8v2.775q0 .675-.612.938T10.3 18.3L7 15H4q-.425 0-.712-.288T3 14v-4q0-.425.288-.712T4 9h2.2L2.1 4.9q-.275-.275-.275-.7t.275-.7t.7-.275t.7.275l17 17q.275.275.275.7t-.275.7t-.7.275t-.7-.275zm2.225-7.6q0-2.075-1.1-3.787t-2.95-2.563q-.375-.175-.55-.537t-.05-.738q.15-.4.538-.575t.787 0Q18.1 4.85 19.55 7.05T21 11.975q0 .825-.15 1.638t-.425 1.562q-.2.55-.612.688t-.763.012t-.562-.45t-.013-.75q.275-.65.4-1.312T19 11.975m-4.225-3.55Q15.6 8.95 16.05 10t.45 2v.25q0 .125-.025.25q-.05.325-.35.425t-.55-.15L14.3 11.5q-.15-.15-.225-.337T14 10.775V8.85q0-.3.263-.437t.512.012M9.75 6.95Q9.6 6.8 9.6 6.6t.15-.35l.55-.55q.475-.475 1.087-.213t.613.938V8q0 .35-.3.475t-.55-.125z
158158
</Geometry>
159+
<Geometry x:Key="IconErrorCross">
160+
m11.25 4.75l-6.5 6.5m0-6.5l6.5 6.5
161+
</Geometry>
162+
<Geometry x:Key="IconErrorCircle">
163+
M12 17q.425 0 .713-.288T13 16q0-.425-.288-.713T12 15q-.425 0-.713.288T11 16q0 .425.288.713T12 17Zm0 5q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22Zm0-9q.425 0 .713-.288T13 12V8q0-.425-.288-.713T12 7q-.425 0-.713.288T11 8v4q0 .425.288.713T12 13Z
164+
</Geometry>
159165
<!--EndGameSettings-->
160166

161167
<!--StartGameView-->

gamevault/Windows/LoginWindow.xaml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,19 @@
186186
<TextBlock Text="Specify Your Server URL" TextDecorations="Underline" Margin="0,15,0,5"/>
187187
<StackPanel Orientation="Horizontal" Margin="0,0,0,0">
188188
<TextBox Text="{Binding LoginUser.ServerUrl}" mah:ControlsHelper.CornerRadius="5" BorderThickness="2" Width="400" TextChanged="ServerUrlInput_TextChanged" KeyDown="UserLoginTextBox_KeyDown"/>
189-
<Path Data="{StaticResource IconCheck}" Fill="Green" Margin="2,1,-25,0">
189+
<Path Margin="2,1,-25,0">
190190
<Path.Style>
191191
<Style TargetType="Path">
192-
<Setter Property="Visibility" Value="Collapsed"/>
193192
<Style.Triggers>
194193
<DataTrigger Binding="{Binding LoginServerInfo.IsAvailable}" Value="True">
195-
<Setter Property="Visibility" Value="Visible"/>
194+
<Setter Property="Data" Value="{StaticResource IconCheck}"/>
195+
<Setter Property="Fill" Value="Green"/>
196+
</DataTrigger>
197+
<DataTrigger Binding="{Binding LoginServerInfo.HasError}" Value="True">
198+
<Setter Property="Data" Value="{StaticResource IconErrorCircle}"/>
199+
<Setter Property="Fill" Value="IndianRed"/>
200+
<Setter Property="ToolTip" Value="{Binding LoginServerInfo.ErrorMessage}"/>
201+
<Setter Property="Cursor" Value="Help"/>
196202
</DataTrigger>
197203
</Style.Triggers>
198204
</Style>
@@ -245,13 +251,19 @@
245251
<TextBlock Text="Specify Your Server URL" TextDecorations="Underline" Margin="0,15,0,5"/>
246252
<StackPanel Orientation="Horizontal">
247253
<TextBox Text="{Binding SignupUser.ServerUrl}" mah:ControlsHelper.CornerRadius="5" Width="400" BorderThickness="2" TextChanged="ServerUrlInput_TextChanged" KeyDown="UserRegistrationTextBox_KeyDown"/>
248-
<Path Data="{StaticResource IconCheck}" Fill="Green" Margin="2,1,-25,0">
254+
<Path Margin="2,1,-25,0">
249255
<Path.Style>
250256
<Style TargetType="Path">
251-
<Setter Property="Visibility" Value="Collapsed"/>
252257
<Style.Triggers>
253258
<DataTrigger Binding="{Binding SignUpServerInfo.IsAvailable}" Value="True">
254-
<Setter Property="Visibility" Value="Visible"/>
259+
<Setter Property="Data" Value="{StaticResource IconCheck}"/>
260+
<Setter Property="Fill" Value="Green"/>
261+
</DataTrigger>
262+
<DataTrigger Binding="{Binding SignUpServerInfo.HasError}" Value="True">
263+
<Setter Property="Data" Value="{StaticResource IconErrorCircle}"/>
264+
<Setter Property="Fill" Value="IndianRed"/>
265+
<Setter Property="ToolTip" Value="{Binding SignUpServerInfo.ErrorMessage}"/>
266+
<Setter Property="Cursor" Value="Help"/>
255267
</DataTrigger>
256268
</Style.Triggers>
257269
</Style>
@@ -401,7 +413,7 @@
401413
</StackPanel>
402414
<Button Style="{StaticResource ButtonWrapper}" Height="30" Width="30" Cursor="Hand" Click="RemoveAdditionalRequestHeader_Click">
403415
<Grid Style="{DynamicResource HoverEffect}" Background="Transparent" RenderTransformOrigin="0.5,0.5">
404-
<Path Data="m11.25 4.75l-6.5 6.5m0-6.5l6.5 6.5" Stroke="IndianRed" StrokeThickness="2">
416+
<Path Data="{StaticResource IconErrorCross}" Stroke="IndianRed" StrokeThickness="2">
405417
<Path.RenderTransform>
406418
<ScaleTransform ScaleX="2" ScaleY="2"/>
407419
</Path.RenderTransform>

gamevault/Windows/LoginWindow.xaml.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,17 @@ private async void ServerUrlInput_Tick(object sender, EventArgs e)
140140
ViewModel.SignUpServerInfo = new BindableServerInfo(serverInfo);
141141
}
142142
}
143-
catch
143+
catch (Exception ex)
144144
{
145-
ViewModel.LoginServerInfo = new BindableServerInfo();
145+
string message = WebExceptionHelper.TryGetServerMessage(ex);
146+
if (ViewModel.LoginStepIndex == (int)LoginStep.SignIn)
147+
{
148+
ViewModel.LoginServerInfo = new BindableServerInfo(message == "" ? "Could not connect to server" : message);
149+
}
150+
else if (ViewModel.LoginStepIndex == (int)LoginStep.SignUp)
151+
{
152+
ViewModel.SignUpServerInfo = new BindableServerInfo(message == "" ? "Could not connect to server" : message);
153+
}
146154
}
147155
}
148156
private void ServerUrlInput_TextChanged(object sender, RoutedEventArgs e)
@@ -333,7 +341,7 @@ private async Task LoadMainWindow(UserProfile profile)
333341
}
334342
private async void SaveAndSignUp_Click(object sender, RoutedEventArgs e)
335343
{
336-
await SaveAndSignUp();
344+
await SaveAndSignUp();
337345
}
338346
private async Task SaveAndSignUp()
339347
{

0 commit comments

Comments
 (0)