|
6 | 6 | using System.Net;
|
7 | 7 | using System.Reflection;
|
8 | 8 | using System.Threading.Tasks;
|
| 9 | +using log4net.Core; |
9 | 10 |
|
10 | 11 | namespace Abot.Core
|
11 | 12 | {
|
@@ -103,24 +104,32 @@ public virtual CrawledPage MakeRequest(Uri uri, Func<CrawledPage, CrawlDecision>
|
103 | 104 | }
|
104 | 105 | finally
|
105 | 106 | {
|
106 |
| - crawledPage.HttpWebRequest = request; |
107 |
| - crawledPage.RequestCompleted = DateTime.Now; |
108 |
| - if (response != null) |
| 107 | + try |
109 | 108 | {
|
110 |
| - crawledPage.HttpWebResponse = new HttpWebResponseWrapper(response); |
111 |
| - CrawlDecision shouldDownloadContentDecision = shouldDownloadContent(crawledPage); |
112 |
| - if (shouldDownloadContentDecision.Allow) |
| 109 | + crawledPage.HttpWebRequest = request; |
| 110 | + crawledPage.RequestCompleted = DateTime.Now; |
| 111 | + if (response != null) |
113 | 112 | {
|
114 |
| - crawledPage.DownloadContentStarted = DateTime.Now; |
115 |
| - crawledPage.Content = _extractor.GetContent(response); |
116 |
| - crawledPage.DownloadContentCompleted = DateTime.Now; |
| 113 | + crawledPage.HttpWebResponse = new HttpWebResponseWrapper(response); |
| 114 | + CrawlDecision shouldDownloadContentDecision = shouldDownloadContent(crawledPage); |
| 115 | + if (shouldDownloadContentDecision.Allow) |
| 116 | + { |
| 117 | + crawledPage.DownloadContentStarted = DateTime.Now; |
| 118 | + crawledPage.Content = _extractor.GetContent(response); |
| 119 | + crawledPage.DownloadContentCompleted = DateTime.Now; |
| 120 | + } |
| 121 | + else |
| 122 | + { |
| 123 | + _logger.DebugFormat("Links on page [{0}] not crawled, [{1}]", crawledPage.Uri.AbsoluteUri, shouldDownloadContentDecision.Reason); |
| 124 | + } |
| 125 | + |
| 126 | + response.Close();//Should already be closed by _extractor but just being safe |
117 | 127 | }
|
118 |
| - else |
119 |
| - { |
120 |
| - _logger.DebugFormat("Links on page [{0}] not crawled, [{1}]", crawledPage.Uri.AbsoluteUri, shouldDownloadContentDecision.Reason); |
121 |
| - } |
122 |
| - |
123 |
| - response.Close();//Should already be closed by _extractor but just being safe |
| 128 | + } |
| 129 | + catch (Exception e) |
| 130 | + { |
| 131 | + _logger.DebugFormat("Error occurred finalizing requesting url [{0}]", uri.AbsoluteUri); |
| 132 | + _logger.Debug(e); |
124 | 133 | }
|
125 | 134 | }
|
126 | 135 |
|
|
0 commit comments