Skip to content

Commit

Permalink
- Fix waiting for GoIndex alternatives on errors
Browse files Browse the repository at this point in the history
- Better error handling
  • Loading branch information
KoalaBear84 committed Dec 6, 2020
1 parent 2b5147c commit 2976670
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion OpenDirectoryDownloader.Shared/RateLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task RateLimit()
/// <param name="timeSpan">TimeSpan to add</param>
public void AddDelay(TimeSpan timeSpan)
{
LastRequest.Add(timeSpan);
LastRequest = LastRequest.Add(timeSpan);
}
}
}
24 changes: 16 additions & 8 deletions OpenDirectoryDownloader/Site/GoIndex/Go2IndexParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,26 @@ public static async Task<WebDirectory> ParseIndex(HttpClient httpClient, WebDire
}
}

if (indexResponse.Error == null)
if (indexResponse is null)
{
Console.WriteLine("Password OK!");
Logger.Info("Password OK!");

webDirectory = await ScanIndexAsync(httpClient, webDirectory);
Console.WriteLine("Error. Invalid response. Stopping.");
Logger.Error("Error. Invalid response. Stopping.");
}
else
{
OpenDirectoryIndexer.Session.Parameters.Remove(Constants.Parameters_Password);
Console.WriteLine($"Error. Code: {indexResponse.Error.Code}, Message: {indexResponse.Error.Message}. Stopping.");
Logger.Error($"Error. Code: {indexResponse.Error.Code}, Message: {indexResponse.Error.Message}. Stopping.");
if (indexResponse.Error == null)
{
Console.WriteLine("Password OK!");
Logger.Info("Password OK!");

webDirectory = await ScanIndexAsync(httpClient, webDirectory);
}
else
{
OpenDirectoryIndexer.Session.Parameters.Remove(Constants.Parameters_Password);
Console.WriteLine($"Error. Code: {indexResponse.Error.Code}, Message: {indexResponse.Error.Message}. Stopping.");
Logger.Error($"Error. Code: {indexResponse.Error.Code}, Message: {indexResponse.Error.Message}. Stopping.");
}
}
}
else
Expand Down
26 changes: 17 additions & 9 deletions OpenDirectoryDownloader/Site/GoIndex/GoIndexParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,26 @@ public static async Task<WebDirectory> ParseIndex(HttpClient httpClient, WebDire
}
}

if (indexResponse.Error == null)
if (indexResponse is null)
{
Console.WriteLine("Password OK!");
Logger.Info("Password OK!");

webDirectory = await ScanIndexAsync(httpClient, webDirectory);
Console.WriteLine("Error. Invalid response. Stopping.");
Logger.Error("Error. Invalid response. Stopping.");
}
else
{
OpenDirectoryIndexer.Session.Parameters.Remove(Constants.Parameters_Password);
Console.WriteLine($"Error. Code: {indexResponse.Error.Code}, Message: {indexResponse.Error.Message}. Stopping.");
Logger.Error($"Error. Code: {indexResponse.Error.Code}, Message: {indexResponse.Error.Message}. Stopping.");
if (indexResponse.Error == null)
{
Console.WriteLine("Password OK!");
Logger.Info("Password OK!");

webDirectory = await ScanIndexAsync(httpClient, webDirectory);
}
else
{
OpenDirectoryIndexer.Session.Parameters.Remove(Constants.Parameters_Password);
Console.WriteLine($"Error. Code: {indexResponse.Error.Code}, Message: {indexResponse.Error.Message}. Stopping.");
Logger.Error($"Error. Code: {indexResponse.Error.Code}, Message: {indexResponse.Error.Message}. Stopping.");
}
}
}
else
Expand Down Expand Up @@ -112,7 +120,7 @@ private static async Task<WebDirectory> ScanIndexAsync(HttpClient httpClient, We
try
{
await RateLimiter.RateLimit();

if (!webDirectory.Url.EndsWith("/"))
{
webDirectory.Url += "/";
Expand Down

0 comments on commit 2976670

Please sign in to comment.