diff --git a/src/Modules/WorldRecordModule/Interfaces/IWorldRecordService.cs b/src/Modules/WorldRecordModule/Interfaces/IWorldRecordService.cs
index dca17f43f..baf11cf64 100644
--- a/src/Modules/WorldRecordModule/Interfaces/IWorldRecordService.cs
+++ b/src/Modules/WorldRecordModule/Interfaces/IWorldRecordService.cs
@@ -6,18 +6,19 @@ namespace EvoSC.Modules.Official.WorldRecordModule.Interfaces;
public interface IWorldRecordService
{
///
- /// Trigger a fetch for records from trackmania.io
+ /// Trigger a fetch for records from trackmania.io.
+ /// If an error occurs during the API fetch, the method will log the error and use AT instead.
///
/// The UID of the map to load records from.
///
public Task FetchRecordAsync(string mapUid);
-
+
///
/// Clears the currently loaded world record.
///
///
public Task ClearRecordAsync();
-
+
///
/// Gets the currently loaded world record or null.
///
diff --git a/src/Modules/WorldRecordModule/Services/WorldRecordService.cs b/src/Modules/WorldRecordModule/Services/WorldRecordService.cs
index b67273a5e..a0786f1b7 100644
--- a/src/Modules/WorldRecordModule/Services/WorldRecordService.cs
+++ b/src/Modules/WorldRecordModule/Services/WorldRecordService.cs
@@ -31,18 +31,17 @@ public async Task FetchRecordAsync(string mapUid)
User_Agent = "EvoSC# / World Record Grabber / Discord: chris92"
})
.GetJsonAsync();
-
}
catch (FlurlHttpException ex)
{
- logger.LogError(ex, "Invalid response from Openplanet. Maybe API issues?");
- throw;
+ // Log error regardless of the status code, since any exception means an unexpected outcome
+ logger.LogError(ex, "Error fetching data from trackmania.io API. Status code: {StatusCode}", ex.Call.Response?.StatusCode);
}
-
+
logger.LogDebug("Loaded records for map.");
- if (res is {tops.Count: > 0})
+ if (res is { tops.Count: > 0 })
{
var bestRecord = res.tops.First();
var newWorldRecord = new WorldRecord
@@ -56,7 +55,7 @@ public async Task FetchRecordAsync(string mapUid)
newWorldRecord.PlayerName,
newWorldRecord.Time.ToString()
);
-
+
await OverwriteRecordAsync(newWorldRecord);
}
else
@@ -69,12 +68,12 @@ public async Task FetchRecordAsync(string mapUid)
Time = RaceTime.FromMilliseconds(mapInfo.AuthorTime),
Source = WorldRecordSource.AuthorTime
};
-
+
logger.LogDebug("Couldn't load World Record, using Author Time instead.");
-
+
await OverwriteRecordAsync(newWorldRecord);
}
-
+
}
public Task ClearRecordAsync()
@@ -105,14 +104,14 @@ public async Task DetectNewWorldRecordThroughScoresAsync(ScoresEventArgs scoresE
{
await OverwriteRecordAsync(new WorldRecord
{
- PlayerName = score.Name,
- Time = RaceTime.FromMilliseconds(score.BestRaceTime),
+ PlayerName = score.Name,
+ Time = RaceTime.FromMilliseconds(score.BestRaceTime),
Source = WorldRecordSource.Local
});
}
}
}
-
+
private async Task OverwriteRecordAsync(WorldRecord newRecord)
{
lock (_currentWorldRecordLock)