diff --git a/src/NzbDrone.Core/Download/FailedDownloadService.cs b/src/NzbDrone.Core/Download/FailedDownloadService.cs index 37e05e099..c1d383ce8 100644 --- a/src/NzbDrone.Core/Download/FailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/FailedDownloadService.cs @@ -40,9 +40,13 @@ public void MarkAsFailed(int historyId, string message, string source = null, bo if (downloadId.IsNullOrWhiteSpace()) { - PublishDownloadFailedEvent(history, new List { history.EpisodeId }, message, source, skipRedownload: skipRedownload); + if (history.EventType == EpisodeHistoryEventType.Grabbed) + { + PublishDownloadFailedEvent(history, new List { history.EpisodeId }, message, source, skipRedownload: skipRedownload); + return; + } - return; + throw new InvalidOperationException("Unable to mark download as failed, history item was not grabbed and has no download ID"); } var grabbedHistory = new List(); @@ -57,7 +61,12 @@ public void MarkAsFailed(int historyId, string message, string source = null, bo grabbedHistory.AddRange(GetGrabbedHistory(downloadId)); grabbedHistory = grabbedHistory.DistinctBy(h => h.Id).ToList(); - PublishDownloadFailedEvent(history, GetEpisodeIds(grabbedHistory), message, source); + if (grabbedHistory.Any()) + { + PublishDownloadFailedEvent(grabbedHistory.First(), GetEpisodeIds(grabbedHistory), message, source); + } + + throw new InvalidOperationException("Unable to mark download as failed, no grabbed history available"); } public void MarkAsFailed(TrackedDownload trackedDownload, string message, string source = null, bool skipRedownload = false) @@ -68,6 +77,8 @@ public void MarkAsFailed(TrackedDownload trackedDownload, string message, string { PublishDownloadFailedEvent(history.First(), GetEpisodeIds(history), message ?? "Manually marked as failed", source, trackedDownload, skipRedownload: skipRedownload); } + + throw new InvalidOperationException("Unable to mark download as failed, no grabbed history available"); } public void Check(TrackedDownload trackedDownload) diff --git a/src/Sonarr.Http/ErrorManagement/SonarrErrorPipeline.cs b/src/Sonarr.Http/ErrorManagement/SonarrErrorPipeline.cs index 32786e725..e232f3eca 100644 --- a/src/Sonarr.Http/ErrorManagement/SonarrErrorPipeline.cs +++ b/src/Sonarr.Http/ErrorManagement/SonarrErrorPipeline.cs @@ -1,3 +1,4 @@ +using System; using System.Data.SQLite; using System.Net; using System.Threading.Tasks; @@ -76,6 +77,12 @@ public async Task HandleException(HttpContext context) _logger.Error(sqLiteException, "[{0} {1}]", context.Request.Method, context.Request.Path); } + else if (exception is InvalidOperationException invalidOperationException) + { + _logger.Warn(invalidOperationException, "[{0} {1}]", context.Request.Method, context.Request.Path); + + statusCode = HttpStatusCode.BadRequest; + } else { _logger.Fatal(exception, "Request Failed. {0} {1}", context.Request.Method, context.Request.Path);