Skip to content

Commit

Permalink
Add exception handling to profile viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Simyon264 committed May 1, 2024
1 parent 5433297 commit ff4a710
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Client/Components/Pages/Player.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
{
<p>Loading...</p>
}
else if (FailedToLoad)
{
<p>Failed to load player data. Exception: @Exception.Message</p>
}
else
{
<h1>@playerData.PlayerData.Username</h1>
Expand Down Expand Up @@ -84,11 +88,21 @@ else
[Parameter] public string Guid { get; set; } = string.Empty;

private CollectedPlayerData? playerData;
private bool FailedToLoad { get; set; } = false;
public Exception? Exception { get; set; }

protected override async Task OnInitializedAsync()
{
playerData = await Http.GetFromJsonAsync<CollectedPlayerData>($"api/Data/player-data?guid={Guid}");
playerData.Characters = playerData.Characters.OrderByDescending(x => x.RoundsPlayed).ToList();
playerData.JobCount = playerData.JobCount.OrderByDescending(x => x.RoundsPlayed).ToList();
try
{
playerData = await Http.GetFromJsonAsync<CollectedPlayerData>($"api/Data/player-data?guid={Guid}");
playerData.Characters = playerData.Characters.OrderByDescending(x => x.RoundsPlayed).ToList();
playerData.JobCount = playerData.JobCount.OrderByDescending(x => x.RoundsPlayed).ToList();
}
catch (Exception e)
{
FailedToLoad = true;
Exception = e;
}
}
}

0 comments on commit ff4a710

Please sign in to comment.