Skip to content

Commit f17c4ff

Browse files
committed
Fix profiles erroring when the player never played
Fixes #21
1 parent 92f2e99 commit f17c4ff

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

ReplayBrowser/Helpers/ReplayHelper.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public async Task<CollectedPlayerData> GetPlayerProfile(Guid playerGuid, Authent
105105
});
106106
}
107107

108-
var replayPlayers = await _context.Players
108+
var replayPlayers = await _context.Players
109109
.AsNoTracking()
110110
.Where(p => p.Participant.PlayerGuid == playerGuid)
111111
.Where(p => p.Participant.Replay!.Date != null)
@@ -121,6 +121,27 @@ public async Task<CollectedPlayerData> GetPlayerProfile(Guid playerGuid, Authent
121121
})
122122
.ToListAsync();
123123

124+
if (replayPlayers.Count == 0)
125+
{
126+
return new CollectedPlayerData()
127+
{
128+
PlayerData = new PlayerData()
129+
{
130+
PlayerGuid = playerGuid,
131+
Username = (await _apiHelper.FetchPlayerDataFromGuid(playerGuid)).Username ??
132+
"Unable to fetch username (API error)"
133+
},
134+
PlayerGuid = playerGuid,
135+
Characters = new List<CharacterData>(),
136+
TotalEstimatedPlaytime = TimeSpan.Zero,
137+
TotalRoundsPlayed = 0,
138+
TotalAntagRoundsPlayed = 0,
139+
LastSeen = DateTime.MinValue,
140+
JobCount = new List<JobCountData>(),
141+
GeneratedAt = DateTime.UtcNow
142+
};
143+
}
144+
124145
var replayPlayerGroup = replayPlayers.GroupBy(rp => rp.ReplayId);
125146

126147
var totalRoundsPlayed = replayPlayerGroup.Count();

ReplayBrowser/Pages/Profile.razor

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ else if (IsPrivate)
2323
<h1>Protected data (@Username)</h1>
2424
<p>@(Exception?.Message ?? "No info")</p>
2525
}
26-
else if (FailedToLoad)
27-
{
28-
<h1>Error (@Username)</h1>
29-
<p>Failed to load player data. Exception: @(Exception?.Message ?? "No info")</p>
30-
}
3126
else
3227
{
3328
<MetaDataSpecifer
@@ -197,12 +192,5 @@ else
197192
Exception = e;
198193
_playerData = new();
199194
}
200-
catch (Exception e)
201-
{
202-
FailedToLoad = true;
203-
Exception = e;
204-
_playerData = new();
205-
Log.Error(e, "Failed to load player data.");
206-
}
207195
}
208196
}

0 commit comments

Comments
 (0)