From 8854269a43bf8d5dd59e89cbb15778d0110c5748 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 29 Aug 2012 17:57:23 -0700 Subject: [PATCH] Existing series won't blow up when tvdb dies Fixed: Issues with TheTVDB won't cause the Add Series page to error out --- .../Controllers/AddSeriesController.cs | 28 +++++++++++++------ .../Views/AddSeries/ExistingSeries.cshtml | 9 +++++- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/NzbDrone.Web/Controllers/AddSeriesController.cs b/NzbDrone.Web/Controllers/AddSeriesController.cs index 7a6cb8192..84cf0c434 100644 --- a/NzbDrone.Web/Controllers/AddSeriesController.cs +++ b/NzbDrone.Web/Controllers/AddSeriesController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Web.Mvc; +using NLog; using NzbDrone.Common; using NzbDrone.Core.Jobs; using NzbDrone.Core.Providers; @@ -23,6 +24,8 @@ namespace NzbDrone.Web.Controllers private readonly TvDbProvider _tvDbProvider; private readonly DiskProvider _diskProvider; + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + public AddSeriesController(RootDirProvider rootFolderProvider, ConfigProvider configProvider, QualityProvider qualityProvider, TvDbProvider tvDbProvider, @@ -83,17 +86,26 @@ namespace NzbDrone.Web.Controllers foreach (var folder in unmappedList) { var foldername = new DirectoryInfo(folder).Name; - var tvdbResult = _tvDbProvider.SearchSeries(foldername).FirstOrDefault(); - var title = String.Empty; - var seriesId = 0; - if (tvdbResult != null) + try { - title = tvdbResult.SeriesName; - seriesId = tvdbResult.Id; - } + var tvdbResult = _tvDbProvider.SearchSeries(foldername).FirstOrDefault(); - result.ExistingSeries.Add(new Tuple(folder, title, seriesId)); + var title = String.Empty; + var seriesId = 0; + if (tvdbResult != null) + { + title = tvdbResult.SeriesName; + seriesId = tvdbResult.Id; + } + + result.ExistingSeries.Add(new Tuple(folder, title, seriesId)); + } + catch(Exception ex) + { + logger.WarnException("Failed to connect to TheTVDB to search for: " + foldername, ex); + return View(); + } } var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile); diff --git a/NzbDrone.Web/Views/AddSeries/ExistingSeries.cshtml b/NzbDrone.Web/Views/AddSeries/ExistingSeries.cshtml index 45e12b0bd..1e95d2ddd 100644 --- a/NzbDrone.Web/Views/AddSeries/ExistingSeries.cshtml +++ b/NzbDrone.Web/Views/AddSeries/ExistingSeries.cshtml @@ -6,7 +6,14 @@ Layout = null; } -@if (Model.ExistingSeries.Count == 0) +@if (Model == null) +{ +

+ Error searching TheTVDB, please try again later. +

+} + +else if (!Model.ExistingSeries.Any()) {

No series available. Try adding a new Root Folder.