From c7d3a072198bf37e9a408c3476bf9ab90054a552 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 6 Aug 2013 23:16:28 -0700 Subject: [PATCH] Throw a custom error for trakt so it doesn't die in LINQ --- .../Trakt/TraktCommunicationException.cs | 14 ++++++++++++++ NzbDrone.Core/MetadataSource/TraktProxy.cs | 13 +++++++++++++ NzbDrone.Core/NzbDrone.Core.csproj | 1 + 3 files changed, 28 insertions(+) create mode 100644 NzbDrone.Core/MetadataSource/Trakt/TraktCommunicationException.cs diff --git a/NzbDrone.Core/MetadataSource/Trakt/TraktCommunicationException.cs b/NzbDrone.Core/MetadataSource/Trakt/TraktCommunicationException.cs new file mode 100644 index 000000000..d09dad66c --- /dev/null +++ b/NzbDrone.Core/MetadataSource/Trakt/TraktCommunicationException.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core.MetadataSource.Trakt +{ + public class TraktCommunicationException : Exception + { + public TraktCommunicationException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/NzbDrone.Core/MetadataSource/TraktProxy.cs b/NzbDrone.Core/MetadataSource/TraktProxy.cs index 15cfc87d1..99bfd09da 100644 --- a/NzbDrone.Core/MetadataSource/TraktProxy.cs +++ b/NzbDrone.Core/MetadataSource/TraktProxy.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Text.RegularExpressions; using NzbDrone.Common; using NzbDrone.Core.MediaCover; @@ -20,6 +21,8 @@ public List SearchForNewSeries(string title) var restRequest = new RestRequest(title.ToSearchTerm()); var response = client.Execute>(restRequest); + CheckForError(response); + return response.Data.Select(MapSeries).ToList(); } @@ -29,6 +32,8 @@ public Tuple> GetSeriesInfo(int tvDbSeriesId) var restRequest = new RestRequest(tvDbSeriesId.ToString() + "/extended"); var response = client.Execute(restRequest); + CheckForError(response); + var episodes = response.Data.seasons.SelectMany(c => c.episodes).Select(MapEpisode).ToList(); var series = MapSeries(response.Data); @@ -120,5 +125,13 @@ private static string FromIsoToString(string iso) return match.Captures[0].Value; } + + private void CheckForError(IRestResponse response) + { + if (response.StatusCode != HttpStatusCode.OK) + { + throw new TraktCommunicationException(response.ErrorMessage, response.ErrorException); + } + } } } \ No newline at end of file diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 2ff65b46a..b717a5269 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -230,6 +230,7 @@ +