Fixed: Don't crap on bad searches

pull/3962/head
Qstick 5 years ago
parent 5d2ac0b86b
commit fcb31ac51b

@ -86,6 +86,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
request.SuppressHttpError = true;
var response = _httpClient.Get<MovieResourceRoot>(request);
if (response.StatusCode == HttpStatusCode.NotFound)
{
throw new MovieNotFoundException("Movie not found.");
@ -305,15 +306,18 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
// request.SuppressHttpError = true;
var response = _httpClient.Get<FindRoot>(request);
if (response.StatusCode != HttpStatusCode.OK)
if (response.HasHttpError)
{
throw new HttpException(request, response);
if (response.StatusCode == HttpStatusCode.NotFound)
{
throw new MovieNotFoundException(imdbId);
}
if (response.Headers.ContentType != HttpAccept.JsonCharset.Value)
else
{
throw new HttpException(request, response);
}
}
// The dude abides, so should us, Lets be nice to TMDb
// var allowed = int.Parse(response.Headers.GetValues("X-RateLimit-Limit").First()); // get allowed
@ -328,9 +332,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
}
}
var resources = response.Resource;
var resource = response.Resource.movie_results.FirstOrDefault();
return resources.movie_results.SelectList(MapMovie).FirstOrDefault();
return MapMovie(resource);
}
public List<Movie> DiscoverNewMovies(string action)
@ -380,6 +384,8 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
}
public List<Movie> SearchForNewMovie(string title)
{
try
{
var lowerTitle = title.ToLower();
@ -478,6 +484,16 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
return movieResults.SelectList(MapMovie);
}
catch (HttpException)
{
throw new SkyHookException("Search for '{0}' failed. Unable to communicate with TMDb.", title);
}
catch (Exception ex)
{
_logger.Warn(ex, ex.Message);
throw new SkyHookException("Search for '{0}' failed. Invalid response received from TMDb.", title);
}
}
public Movie MapMovie(MovieResult result)
{

Loading…
Cancel
Save