Skip to content

Commit

Permalink
Add try..catch so the application won't fail on exceptions (fix #16) (#…
Browse files Browse the repository at this point in the history
…22)

Especially about HTTP exceptions, which are ignored and the application
is trying another time after a usual sleeping time.
  • Loading branch information
ktos authored Apr 6, 2020
1 parent c0387a3 commit 1a491fd
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,46 @@ private static void Main(string[] args)

if (isRunSet)
{
bot.AnalyzePostsByIdsAsync(runSet).Wait();
try
{
bot.AnalyzePostsByIdsAsync(runSet).Wait();
}
catch (AggregateException e)
{
logger.LogError($"HTTP Exception: {e.Message}");
}
return;
}

if (isRunOnce)
{
bot.AnalyzeNewPostsAsync().Wait();
logger.LogDebug("Single run completed.");
try
{
bot.AnalyzeNewPostsAsync().Wait();
logger.LogDebug("Single run completed.");
}
catch (AggregateException e)
{
logger.LogError($"HTTP Exception: {e.Message}");
}
}
else
{
while (true)
{
bot.AnalyzeNewPostsAsync().Wait();
logger.LogDebug("Going to sleep for {0} minutes", timeBetweenUpdates);

Task.Delay(TimeSpan.FromMinutes(timeBetweenUpdates)).Wait();
try
{
bot.AnalyzeNewPostsAsync().Wait();
}
catch (AggregateException e)
{
logger.LogError($"HTTP Exception: {e.Message}");
}
finally
{
logger.LogDebug("Going to sleep for {0} minutes", timeBetweenUpdates);
Task.Delay(TimeSpan.FromMinutes(timeBetweenUpdates)).Wait();
}
}
}

Expand Down

0 comments on commit 1a491fd

Please sign in to comment.