Skip to content

Commit

Permalink
Merge pull request #182 from DennisvHest/175-fix-404-error-for-player…
Browse files Browse the repository at this point in the history
…s-that-have-no-scores-yet-in-scoresaber

Fixed errors for beginner ScoreSaber players
  • Loading branch information
DennisvHest committed Jun 23, 2024
2 parents 74bec71 + 7d9b268 commit 902b94a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion MapMaven.Core/Models/PlayerProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public PlayerProfile(ApiClients.ScoreSaber.Player player)
LeaderboardProvider = LeaderboardProvider.ScoreSaber;

var playerRankHistory = player.Histories
?.Split(',')
?.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse)
.Cast<int?>()
.ToArray() ?? [];
Expand Down
31 changes: 24 additions & 7 deletions MapMaven.Core/Services/Leaderboards/ScoreSaberService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,30 @@ public class ScoreSaberService : ILeaderboardProviderService
do
{
var scoreCollection = await _scoreSaber.ScoresAsync(
playerId: playerId,
limit: 100,
sort: Sort.Top,
page: page,
withMetadata: true
);
PlayerScoreCollection scoreCollection;
try
{
scoreCollection = await _scoreSaber.ScoresAsync(
playerId: playerId,
limit: 100,
sort: Sort.Top,
page: page,
withMetadata: true
);
}
catch (ScoreSaberApiClient.ApiException exception)
{
// The ScoreSaber API returns 404 when player has no scores, so just return an empty list of PlayerScores.
if (exception.StatusCode == 404)
{
break;
}
else
{
throw;
}
}
totalScores = scoreCollection.Metadata.Total;
Expand Down

0 comments on commit 902b94a

Please sign in to comment.