1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Throw a custom error for trakt so it doesn't die in LINQ

This commit is contained in:
Mark McDowall 2013-08-06 23:16:28 -07:00
parent 7de7b7d599
commit c7d3a07219
3 changed files with 28 additions and 0 deletions

View File

@ -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)
{
}
}
}

View File

@ -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<Series> SearchForNewSeries(string title)
var restRequest = new RestRequest(title.ToSearchTerm());
var response = client.Execute<List<Show>>(restRequest);
CheckForError(response);
return response.Data.Select(MapSeries).ToList();
}
@ -29,6 +32,8 @@ public Tuple<Series, List<Episode>> GetSeriesInfo(int tvDbSeriesId)
var restRequest = new RestRequest(tvDbSeriesId.ToString() + "/extended");
var response = client.Execute<Show>(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);
}
}
}
}

View File

@ -230,6 +230,7 @@
<Compile Include="MediaFiles\Events\SeriesRenamedEvent.cs" />
<Compile Include="MediaFiles\RenameEpisodeFileService.cs" />
<Compile Include="MediaFiles\UpgradeMediaFileService.cs" />
<Compile Include="MetadataSource\Trakt\TraktCommunicationException.cs" />
<Compile Include="Notifications\Email\TestEmailCommand.cs" />
<Compile Include="Notifications\Growl\GrowlSettings.cs" />
<Compile Include="Notifications\Growl\TestGrowlCommand.cs" />