mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 10:32:35 +01:00
Better client side errors when there are issues communicating with trakt.
This commit is contained in:
parent
377e5d28e9
commit
0c57c6a6c1
@ -9,7 +9,6 @@ public abstract class ApiException : Exception
|
||||
{
|
||||
public object Content { get; private set; }
|
||||
|
||||
|
||||
public HttpStatusCode StatusCode { get; private set; }
|
||||
|
||||
protected ApiException(HttpStatusCode statusCode, object content = null)
|
||||
|
@ -3,6 +3,7 @@
|
||||
using NLog;
|
||||
using Nancy;
|
||||
using NzbDrone.Api.Extensions;
|
||||
using NzbDrone.Common.Exceptions;
|
||||
using HttpStatusCode = Nancy.HttpStatusCode;
|
||||
|
||||
namespace NzbDrone.Api.ErrorManagement
|
||||
@ -35,9 +36,20 @@ public Response HandleException(NancyContext context, Exception exception)
|
||||
return validationException.Errors.AsResponse(HttpStatusCode.BadRequest);
|
||||
}
|
||||
|
||||
var clientException = exception as NzbDroneClientException;
|
||||
|
||||
if (clientException != null)
|
||||
{
|
||||
return new ErrorModel
|
||||
{
|
||||
Message = exception.Message,
|
||||
Description = exception.ToString()
|
||||
}.AsResponse((HttpStatusCode)clientException.StatusCode);
|
||||
}
|
||||
|
||||
_logger.FatalException("Request Failed", exception);
|
||||
|
||||
return new ErrorModel()
|
||||
return new ErrorModel
|
||||
{
|
||||
Message = exception.Message,
|
||||
Description = exception.ToString()
|
||||
|
20
NzbDrone.Common/Exceptions/NzbDroneClientException.cs
Normal file
20
NzbDrone.Common/Exceptions/NzbDroneClientException.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Net;
|
||||
|
||||
namespace NzbDrone.Common.Exceptions
|
||||
{
|
||||
public class NzbDroneClientException : NzbDroneException
|
||||
{
|
||||
public HttpStatusCode StatusCode { get; private set; }
|
||||
|
||||
public NzbDroneClientException(HttpStatusCode statusCode, string message, params object[] args) : base(message, args)
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
}
|
||||
|
||||
public NzbDroneClientException(HttpStatusCode statusCode, string message)
|
||||
: base(message)
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace NzbDrone.Common.Exceptions
|
||||
{
|
||||
|
||||
|
||||
public abstract class NzbDroneException : ApplicationException
|
||||
{
|
||||
protected NzbDroneException(string message, params object[] args)
|
||||
|
@ -88,6 +88,7 @@
|
||||
<Compile Include="EnvironmentInfo\StartupArguments.cs" />
|
||||
<Compile Include="EnvironmentInfo\RuntimeInfo.cs" />
|
||||
<Compile Include="EnvironmentInfo\OsInfo.cs" />
|
||||
<Compile Include="Exceptions\NzbDroneClientException.cs" />
|
||||
<Compile Include="Exceptions\NzbDroneException.cs" />
|
||||
<Compile Include="IEnumerableExtensions.cs" />
|
||||
<Compile Include="Instrumentation\GlobalExceptionHandlers.cs" />
|
||||
|
@ -1,14 +0,0 @@
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
20
NzbDrone.Core/MetadataSource/Trakt/TraktException.cs
Normal file
20
NzbDrone.Core/MetadataSource/Trakt/TraktException.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using NzbDrone.Common.Exceptions;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.Trakt
|
||||
{
|
||||
public class TraktException : NzbDroneClientException
|
||||
{
|
||||
public TraktException(string message) : base(HttpStatusCode.ServiceUnavailable, message)
|
||||
{
|
||||
}
|
||||
|
||||
public TraktException(string message, params object[] args) : base(HttpStatusCode.ServiceUnavailable, message, args)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MetadataSource.Trakt;
|
||||
@ -15,7 +17,17 @@ namespace NzbDrone.Core.MetadataSource
|
||||
{
|
||||
public class TraktProxy : ISearchForNewSeries, IProvideSeriesInfo
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
private static readonly Regex InvalidSearchCharRegex = new Regex(@"[^a-zA-Z0-9\s-\.]", RegexOptions.Compiled);
|
||||
|
||||
public TraktProxy(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<Series> SearchForNewSeries(string title)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = BuildClient("search", "shows");
|
||||
var restRequest = new RestRequest(GetSearchTerm(title));
|
||||
@ -23,18 +35,15 @@ public List<Series> SearchForNewSeries(string title)
|
||||
|
||||
return response.Select(MapSearchSeries).ToList();
|
||||
}
|
||||
|
||||
|
||||
private static readonly Regex InvalidSearchCharRegex = new Regex(@"[^a-zA-Z0-9\s-\.]", RegexOptions.Compiled);
|
||||
|
||||
private static string GetSearchTerm(string phrase)
|
||||
catch (WebException ex)
|
||||
{
|
||||
phrase = phrase.RemoveAccent().ToLower();
|
||||
phrase = phrase.Replace("&", "and");
|
||||
phrase = InvalidSearchCharRegex.Replace(phrase, string.Empty);
|
||||
phrase = phrase.CleanSpaces().Replace(" ", "+");
|
||||
|
||||
return phrase;
|
||||
throw new TraktException("Search for '{0}' failed. Unable to communicate with Trakt.", title);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.WarnException(ex.Message, ex);
|
||||
throw new TraktException("Search for '{0}' failed. Invalid response received from Trakt.", title);
|
||||
}
|
||||
}
|
||||
|
||||
public Tuple<Series, List<Episode>> GetSeriesInfo(int tvDbSeriesId)
|
||||
@ -43,7 +52,6 @@ public Tuple<Series, List<Episode>> GetSeriesInfo(int tvDbSeriesId)
|
||||
var restRequest = new RestRequest(tvDbSeriesId.ToString() + "/extended");
|
||||
var response = client.ExecuteAndValidate<Show>(restRequest);
|
||||
|
||||
|
||||
var episodes = response.seasons.SelectMany(c => c.episodes).Select(MapEpisode).ToList();
|
||||
var series = MapSeries(response);
|
||||
|
||||
@ -164,6 +172,14 @@ private static string FromIsoToString(string iso)
|
||||
return match.Captures[0].Value;
|
||||
}
|
||||
|
||||
private static string GetSearchTerm(string phrase)
|
||||
{
|
||||
phrase = phrase.RemoveAccent().ToLower();
|
||||
phrase = phrase.Replace("&", "and");
|
||||
phrase = InvalidSearchCharRegex.Replace(phrase, string.Empty);
|
||||
phrase = phrase.CleanSpaces().Replace(" ", "+");
|
||||
|
||||
return phrase;
|
||||
}
|
||||
}
|
||||
}
|
@ -223,6 +223,7 @@
|
||||
<Compile Include="Instrumentation\Commands\DeleteLogFilesCommand.cs" />
|
||||
<Compile Include="Instrumentation\Commands\TrimLogCommand.cs" />
|
||||
<Compile Include="Instrumentation\DeleteLogFilesService.cs" />
|
||||
<Compile Include="MetadataSource\Trakt\TraktException.cs" />
|
||||
<Compile Include="ProgressMessaging\NewProgressMessageEvent.cs" />
|
||||
<Compile Include="ProgressMessaging\ProgressMessage.cs" />
|
||||
<Compile Include="ProgressMessaging\ProgressMessageTarget.cs" />
|
||||
@ -251,7 +252,6 @@
|
||||
<Compile Include="MediaFiles\RenameEpisodeFileService.cs" />
|
||||
<Compile Include="MediaFiles\SameFilenameException.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" />
|
||||
|
@ -73,8 +73,14 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
else if (xmlHttpRequest.status === 503) {
|
||||
message.message = xmlHttpRequest.responseJSON.message;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
message.message = '[{0}] {1} : {2}'.format(ajaxOptions.type, xmlHttpRequest.statusText, ajaxOptions.url);
|
||||
}
|
||||
|
||||
window.Messenger().post(message);
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user