added try catch for when a site could be down or blocking requests
This commit is contained in:
parent
fd60906a20
commit
008d79cf3d
@ -36,11 +36,19 @@ public class HtmlPageReader
|
|||||||
private string ReadSiteContent(string url)
|
private string ReadSiteContent(string url)
|
||||||
{
|
{
|
||||||
using var client = new HttpClient();
|
using var client = new HttpClient();
|
||||||
var html = client.GetStringAsync(url);
|
try
|
||||||
html.Wait();
|
{
|
||||||
|
var html = client.GetStringAsync(url);
|
||||||
|
html.Wait();
|
||||||
|
|
||||||
var content = html.Result;
|
var content = html.Result;
|
||||||
return content;
|
return content;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Failed to connect to '{url}'. {ex.Message}");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetSiteContent()
|
public string GetSiteContent()
|
||||||
|
Loading…
Reference in New Issue
Block a user