From d5da0ec4dd4680e7d69fa7b1ed49794744b9b7ae Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Tue, 30 Dec 2014 21:28:46 -0800 Subject: [PATCH] fixed: return proper error when searching for invalid tvdb id. --- .../TvdbDataProxyFixture.cs | 10 +++++++--- src/NzbDrone.Core/MetadataSource/TvDbProxy.cs | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core.Test/MetadataSourceTests/TvdbDataProxyFixture.cs b/src/NzbDrone.Core.Test/MetadataSourceTests/TvdbDataProxyFixture.cs index bf4df218d..fee5c4785 100644 --- a/src/NzbDrone.Core.Test/MetadataSourceTests/TvdbDataProxyFixture.cs +++ b/src/NzbDrone.Core.Test/MetadataSourceTests/TvdbDataProxyFixture.cs @@ -44,10 +44,14 @@ namespace NzbDrone.Core.Test.MetadataSourceTests result[0].Title.Should().Be(expected); } - [Test] - public void no_search_result() + [TestCase("tvdbid:")] + [TestCase("tvdbid: 99999999999999999999")] + [TestCase("tvdbid: 0")] + [TestCase("tvdbid: -12")] + [TestCase("adjalkwdjkalwdjklawjdlKAJD;EF")] + public void no_search_result(string term) { - var result = Subject.SearchForNewSeries(Guid.NewGuid().ToString()); + var result = Subject.SearchForNewSeries(term); result.Should().BeEmpty(); } diff --git a/src/NzbDrone.Core/MetadataSource/TvDbProxy.cs b/src/NzbDrone.Core/MetadataSource/TvDbProxy.cs index 904dece74..5561cbcf7 100644 --- a/src/NzbDrone.Core/MetadataSource/TvDbProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/TvDbProxy.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Text.RegularExpressions; using System.Web; using NLog; @@ -37,12 +38,26 @@ namespace NzbDrone.Core.MetadataSource int tvdbId; - if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || !Int32.TryParse(slug, out tvdbId)) + if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || !Int32.TryParse(slug, out tvdbId) || tvdbId <= 0) { return Enumerable.Empty(); } - return new[] { _tvdb.GetShow(tvdbId) }; + try + { + return new[] { _tvdb.GetShow(tvdbId) }; + } + catch (WebException ex) + { + var resp = ex.Response as HttpWebResponse; + + if (resp != null && resp.StatusCode == HttpStatusCode.NotFound) + { + return Enumerable.Empty(); + } + + throw; + } } return _tvdb.Search(GetSearchTerm(lowerTitle), 10);