Log partial indexer response on parser error.

This commit is contained in:
Taloth Saldono 2015-05-01 23:51:31 +02:00
parent 2e6cf2b7f6
commit 25c77711cd
2 changed files with 34 additions and 16 deletions

View File

@ -13,7 +13,7 @@ namespace NzbDrone.Core.Indexers.Newznab
protected override bool PreProcess(IndexerResponse indexerResponse) protected override bool PreProcess(IndexerResponse indexerResponse)
{ {
var xdoc = XDocument.Parse(indexerResponse.Content); var xdoc = LoadXmlDocument(indexerResponse);
var error = xdoc.Descendants("error").FirstOrDefault(); var error = xdoc.Descendants("error").FirstOrDefault();
if (error == null) return true; if (error == null) return true;

View File

@ -42,30 +42,48 @@ namespace NzbDrone.Core.Indexers
return releases; return releases;
} }
using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true })) var document = LoadXmlDocument(indexerResponse);
var items = GetItems(document);
foreach (var item in items)
{ {
var document = XDocument.Load(xmlTextReader); try
var items = GetItems(document);
foreach (var item in items)
{ {
try var reportInfo = ProcessItem(item);
{
var reportInfo = ProcessItem(item);
releases.AddIfNotNull(reportInfo); releases.AddIfNotNull(reportInfo);
} }
catch (Exception itemEx) catch (Exception itemEx)
{ {
itemEx.Data.Add("Item", item.Title()); itemEx.Data.Add("Item", item.Title());
_logger.ErrorException("An error occurred while processing feed item from " + indexerResponse.Request.Url, itemEx); _logger.ErrorException("An error occurred while processing feed item from " + indexerResponse.Request.Url, itemEx);
}
} }
} }
return releases; return releases;
} }
protected virtual XDocument LoadXmlDocument(IndexerResponse indexerResponse)
{
try
{
using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true }))
{
return XDocument.Load(xmlTextReader);
}
}
catch (XmlException ex)
{
var contentSample = indexerResponse.Content.Substring(0, Math.Min(indexerResponse.Content.Length, 512));
_logger.Debug("Truncated response content (originally {0} characters): {1}", indexerResponse.Content.Length, contentSample);
ex.Data.Add("ContentLength", indexerResponse.Content.Length);
ex.Data.Add("ContentSample", contentSample);
throw;
}
}
protected virtual ReleaseInfo CreateNewReleaseInfo() protected virtual ReleaseInfo CreateNewReleaseInfo()
{ {
return new ReleaseInfo(); return new ReleaseInfo();