Throw MovieDbException if movie ID not found
Rather than pass a seemingly valid object back to the caller, this change will throw a "MOVIE_ID_NOT_FOUND" exception to the caller. Affects getMovieInfo and getMovieInfoImdb methods Fixes #8
This commit is contained in:
@@ -477,6 +477,8 @@ public class TheMovieDbApi {
|
||||
*
|
||||
* It will return the single highest rated poster and backdrop.
|
||||
*
|
||||
* MovieDbExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies found.
|
||||
*
|
||||
* @param movieId
|
||||
* @param language
|
||||
* @throws MovieDbException
|
||||
@@ -495,7 +497,12 @@ public class TheMovieDbApi {
|
||||
URL url = apiUrl.buildUrl();
|
||||
String webpage = requestWebPage(url);
|
||||
try {
|
||||
return mapper.readValue(webpage, MovieDb.class);
|
||||
MovieDb movie = mapper.readValue(webpage, MovieDb.class);
|
||||
if (movie == null || movie.getId() == 0) {
|
||||
LOG.warn("No movie foind for ID '{}'", movieId);
|
||||
throw new MovieDbException(MovieDbExceptionType.MOVIE_ID_NOT_FOUND, "No movie foind for ID: " + movieId);
|
||||
}
|
||||
return movie;
|
||||
} catch (IOException ex) {
|
||||
LOG.warn("Failed to get movie info: {}", ex.getMessage());
|
||||
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex);
|
||||
@@ -507,6 +514,8 @@ public class TheMovieDbApi {
|
||||
*
|
||||
* It will return the single highest rated poster and backdrop.
|
||||
*
|
||||
* MovieDbExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies found.
|
||||
*
|
||||
* @param imdbId
|
||||
* @param language
|
||||
* @throws MovieDbException
|
||||
@@ -525,7 +534,12 @@ public class TheMovieDbApi {
|
||||
URL url = apiUrl.buildUrl();
|
||||
String webpage = requestWebPage(url);
|
||||
try {
|
||||
return mapper.readValue(webpage, MovieDb.class);
|
||||
MovieDb movie = mapper.readValue(webpage, MovieDb.class);
|
||||
if (movie == null || movie.getId() == 0) {
|
||||
LOG.warn("No movie foind for IMDB ID: '{}'", imdbId);
|
||||
throw new MovieDbException(MovieDbExceptionType.MOVIE_ID_NOT_FOUND, "No movie foind for IMDB ID: " + imdbId);
|
||||
}
|
||||
return movie;
|
||||
} catch (IOException ex) {
|
||||
LOG.warn("Failed to get movie info: {}", ex.getMessage());
|
||||
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex);
|
||||
|
||||
Reference in New Issue
Block a user