Some better null object handling #731

pull/738/head
Jamie.Rees 8 years ago
parent 4e60b4afda
commit 2a56bd2648

@ -47,25 +47,18 @@ namespace PlexRequests.Api
public async Task<List<SearchMovie>> SearchMovie(string searchTerm)
{
var results = await Client.SearchMovie(searchTerm);
return results.Results;
}
[Obsolete("Should use TvMaze for TV")]
public async Task<List<SearchTv>> SearchTv(string searchTerm)
{
var results = await Client.SearchTvShow(searchTerm);
return results.Results;
return results?.Results ?? new List<SearchMovie>();
}
public async Task<List<MovieResult>> GetCurrentPlayingMovies()
{
var movies = await Client.GetMovieList(MovieListType.NowPlaying);
return movies.Results;
return movies?.Results ?? new List<MovieResult>();
}
public async Task<List<MovieResult>> GetUpcomingMovies()
{
var movies = await Client.GetMovieList(MovieListType.Upcoming);
return movies.Results;
return movies?.Results ?? new List<MovieResult>();
}
public async Task<Movie> GetMovieInformation(int tmdbId)
@ -77,14 +70,7 @@ namespace PlexRequests.Api
public async Task<Movie> GetMovieInformation(string imdbId)
{
var movies = await Client.GetMovie(imdbId);
return movies;
}
[Obsolete("Should use TvMaze for TV")]
public async Task<TvShow> GetTvShowInformation(int tmdbId)
{
var show = await Client.GetTvShow(tmdbId);
return show;
return movies ?? new Movie();
}
}
}

@ -147,7 +147,10 @@ namespace PlexRequests.Services.Jobs
var imdbId = PlexHelper.GetProviderIdFromPlexGuid(plexGUID);
var info = _movieApi.GetMovieInformation(imdbId).Result;
if (info == null)
{
throw new Exception($"Movie with Imdb id {imdbId} returned null from the MovieApi");
}
AddImageInsideTable(sb, $"https://image.tmdb.org/t/p/w500{info.BackdropPath}");
sb.Append("<tr>");

@ -257,7 +257,7 @@ namespace PlexRequests.UI.Modules
var movieInfoTask = await MovieApi.GetMovieInformation(movie.Id).ConfigureAwait(false);
// TODO needs to be careful about this, it's adding extra time to search...
// https://www.themoviedb.org/talk/5807f4cdc3a36812160041f2
imdbId = movieInfoTask.ImdbId;
imdbId = movieInfoTask?.ImdbId;
counter++;
}
@ -492,6 +492,15 @@ namespace PlexRequests.UI.Modules
Analytics.TrackEventAsync(Category.Search, Action.Request, "Movie", Username,
CookieHelper.GetAnalyticClientId(Cookies));
var movieInfo = await MovieApi.GetMovieInformation(movieId);
if (movieInfo == null)
{
return
Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "There was an issue adding this movie!"
});
}
var fullMovieName =
$"{movieInfo.Title}{(movieInfo.ReleaseDate.HasValue ? $" ({movieInfo.ReleaseDate.Value.Year})" : string.Empty)}";

Loading…
Cancel
Save