mirror of
https://github.com/Radarr/Radarr
synced 2025-01-04 06:23:32 +00:00
Fixed: Don't crap on bad searches
This commit is contained in:
parent
5d2ac0b86b
commit
fcb31ac51b
1 changed files with 105 additions and 89 deletions
|
@ -86,6 +86,7 @@ public Movie GetMovieInfo(int TmdbId, Profile profile = null, bool hasPreDBEntry
|
|||
request.SuppressHttpError = true;
|
||||
|
||||
var response = _httpClient.Get<MovieResourceRoot>(request);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
throw new MovieNotFoundException("Movie not found.");
|
||||
|
@ -305,14 +306,17 @@ public Movie GetMovieInfo(string imdbId)
|
|||
// request.SuppressHttpError = true;
|
||||
|
||||
var response = _httpClient.Get<FindRoot>(request);
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
|
||||
if (response.HasHttpError)
|
||||
{
|
||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
throw new MovieNotFoundException(imdbId);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new HttpException(request, response);
|
||||
}
|
||||
|
||||
if (response.Headers.ContentType != HttpAccept.JsonCharset.Value)
|
||||
{
|
||||
throw new HttpException(request, response);
|
||||
}
|
||||
|
||||
// The dude abides, so should us, Lets be nice to TMDb
|
||||
|
@ -328,9 +332,9 @@ public Movie GetMovieInfo(string imdbId)
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ private string StripTrailingTheFromTitle(string title)
|
|||
}
|
||||
|
||||
public List<Movie> SearchForNewMovie(string title)
|
||||
{
|
||||
try
|
||||
{
|
||||
var lowerTitle = title.ToLower();
|
||||
|
||||
|
@ -478,6 +484,16 @@ public List<Movie> SearchForNewMovie(string title)
|
|||
|
||||
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…
Reference in a new issue