Skip to content

Commit

Permalink
refactor: handle empty ThunderSkill URL
Browse files Browse the repository at this point in the history
  • Loading branch information
VitaliiAndreev committed Mar 8, 2021
1 parent 2cd0d81 commit fa96a07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Core.Web.WarThunder/Helpers/ThunderSkillParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ public void Load()

var url = Settings.ThunderSkillUrl;

LogDebug(ECoreLogMessage.Reading.Format(url));
if (string.IsNullOrWhiteSpace(url))
{
_mainHtmlNode = GetHtmlDocumentNode(url);
LogWarn("ThunderSkill (TS) URL is empty. Makes sure to copy TS related settings from the default \"Client.Wpf.Settings.xml\".");
}
else
{
LogDebug(ECoreLogMessage.Reading.Format(url));
{
_mainHtmlNode = GetHtmlDocumentNode(url);
}
LogDebug(ECoreLogMessage.FinishedReading.Format(url));
}
LogDebug(ECoreLogMessage.FinishedReading.Format(url));

IsLoaded = true;
}
Expand Down Expand Up @@ -90,7 +97,7 @@ private IDictionary<string, VehicleUsage> GetVehicleUsage(string tableXPath)
if (string.IsNullOrWhiteSpace(tableXPath))
return vehicleUsageRecords;

var table = _mainHtmlNode.SelectSingleNode(tableXPath);
var table = _mainHtmlNode?.SelectSingleNode(tableXPath);

if (table is HtmlNode)
{
Expand Down
3 changes: 3 additions & 0 deletions Core.Web/Helpers/HtmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public HtmlNode GetHtmlDocumentNode(string url, int retryAttempts = EInteger.Num
if (retryAttempts.IsZero())
throw new TimeoutException(EWebLogMessage.FailedToRead.Format(url), internalException);

if (string.IsNullOrWhiteSpace(url))
throw new ArgumentException($"\"{nameof(url)}\" is null or empty.");

try
{
return new HtmlWeb()
Expand Down

0 comments on commit fa96a07

Please # to comment.