Skip to content

Commit fa96a07

Browse files
refactor: handle empty ThunderSkill URL
1 parent 2cd0d81 commit fa96a07

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Core.Web.WarThunder/Helpers/ThunderSkillParser.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@ public void Load()
5454

5555
var url = Settings.ThunderSkillUrl;
5656

57-
LogDebug(ECoreLogMessage.Reading.Format(url));
57+
if (string.IsNullOrWhiteSpace(url))
5858
{
59-
_mainHtmlNode = GetHtmlDocumentNode(url);
59+
LogWarn("ThunderSkill (TS) URL is empty. Makes sure to copy TS related settings from the default \"Client.Wpf.Settings.xml\".");
60+
}
61+
else
62+
{
63+
LogDebug(ECoreLogMessage.Reading.Format(url));
64+
{
65+
_mainHtmlNode = GetHtmlDocumentNode(url);
66+
}
67+
LogDebug(ECoreLogMessage.FinishedReading.Format(url));
6068
}
61-
LogDebug(ECoreLogMessage.FinishedReading.Format(url));
6269

6370
IsLoaded = true;
6471
}
@@ -90,7 +97,7 @@ private IDictionary<string, VehicleUsage> GetVehicleUsage(string tableXPath)
9097
if (string.IsNullOrWhiteSpace(tableXPath))
9198
return vehicleUsageRecords;
9299

93-
var table = _mainHtmlNode.SelectSingleNode(tableXPath);
100+
var table = _mainHtmlNode?.SelectSingleNode(tableXPath);
94101

95102
if (table is HtmlNode)
96103
{

Core.Web/Helpers/HtmlParser.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public HtmlNode GetHtmlDocumentNode(string url, int retryAttempts = EInteger.Num
3333
if (retryAttempts.IsZero())
3434
throw new TimeoutException(EWebLogMessage.FailedToRead.Format(url), internalException);
3535

36+
if (string.IsNullOrWhiteSpace(url))
37+
throw new ArgumentException($"\"{nameof(url)}\" is null or empty.");
38+
3639
try
3740
{
3841
return new HtmlWeb()

0 commit comments

Comments
 (0)