From 6cc05fcca3e6404e76e1d8c5b2955f7119743a06 Mon Sep 17 00:00:00 2001 From: Qstick Date: Tue, 19 Jun 2018 21:44:11 -0400 Subject: [PATCH] Added: Log indexer response to Trace if an exception occurs Co-Authored-By: taloth --- .../Extensions/ExceptionExtensions.cs | 16 ++++++++++++++-- src/NzbDrone.Core/Indexers/HttpIndexerBase.cs | 11 ++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Common/Extensions/ExceptionExtensions.cs b/src/NzbDrone.Common/Extensions/ExceptionExtensions.cs index c719cef3e..bb74db80a 100644 --- a/src/NzbDrone.Common/Extensions/ExceptionExtensions.cs +++ b/src/NzbDrone.Common/Extensions/ExceptionExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -32,7 +32,19 @@ namespace NzbDrone.Common.Extensions { if (response == null || response.Content == null) return ex; - var contentSample = response.Content.Substring(0, Math.Min(response.Content.Length, 512)); + var contentSample = response.Content.Substring(0, Math.Min(response.Content.Length, maxSampleLength)); + + if (response.Request != null) + { + ex.AddData("RequestUri", response.Request.Url.ToString()); + + if (response.Request.ContentSummary != null) + { + ex.AddData("RequestSummary", response.Request.ContentSummary); + } + } + + ex.AddData("StatusCode", response.StatusCode.ToString()); if (response.Headers != null) { diff --git a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs index df6877aca..a8b3120b3 100644 --- a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs @@ -258,7 +258,16 @@ namespace NzbDrone.Core.Indexers { var response = FetchIndexerResponse(request); - return parser.ParseResponse(response).ToList(); + try + { + return parser.ParseResponse(response).ToList(); + } + catch (Exception ex) + { + ex.WithData(response.HttpResponse, 128 * 1024); + _logger.Trace("Unexpected Response content ({0} bytes): {1}", response.HttpResponse.ResponseData.Length, response.HttpResponse.Content); + throw; + } } protected virtual IndexerResponse FetchIndexerResponse(IndexerRequest request)