Skip to content

Commit

Permalink
#198 increase logging verbosity and fix fallback to DataDragon
Browse files Browse the repository at this point in the history
  • Loading branch information
floh22 committed Nov 3, 2022
1 parent 81bfbce commit a1e6bb9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions LeagueBroadcast/Common/Data/Provider/DataDragon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,19 @@ private static async Task GetLatestGameVersion()
GetInstance()._startupContext.Status = "Retrieving latest patch info";
Log.Info("[CDrag] Retrieving latest patch info");

string? rawCDragVersionResponse = JsonDocument.Parse(await RestRequester.GetRaw($"{ConfigController.Component.DataDragon.CDragonRaw}/latest/content-metadata.json")).RootElement.GetProperty("version").GetString();
string? rawCDragVersionResponse = JsonDocument.Parse(await RestRequester.GetRaw($"{ConfigController.Component.DataDragon.CDragonRaw}/latest/content-metadata.json")??"").RootElement.GetProperty("version").GetString();
if (rawCDragVersionResponse is null)
{
Log.Warn($"[CDrag] {$"{ConfigController.Component.DataDragon.CDragonRaw}/latest/content-metadata.json"} unreachable. Is your internet connection working?");
Log.Warn($"[CDrag] Could not get latest CDragon version. Falling back to latest DDrag version");
using JsonDocument response = JsonDocument.Parse(await RestRequester.GetRaw($"https://ddragon.leagueoflegends.com/realms/{ConfigController.Component.DataDragon.Region}.json"), new JsonDocumentOptions { AllowTrailingCommas = true, CommentHandling = JsonCommentHandling.Skip });
using JsonDocument response = JsonDocument.Parse(await RestRequester.GetRaw($"https://ddragon.leagueoflegends.com/realms/{ConfigController.Component.DataDragon.Region}.json")??"", new JsonDocumentOptions { AllowTrailingCommas = true, CommentHandling = JsonCommentHandling.Skip });
rawCDragVersionResponse = response.RootElement.GetProperty("n").GetProperty("champion").ToString();

if(rawCDragVersionResponse is null)
{
Log.Warn($"[CDrag] DDrag not reachable. Assuming internet connection issues. Cannot retrieve data");
return;
}
}
StringVersion localVersion = StringVersion.Parse(rawCDragVersionResponse.Split("+")[0]);
version.localVersion = localVersion;
Expand Down

0 comments on commit a1e6bb9

Please sign in to comment.