From c3edbc2aad6a8567977ad229e1a3de610cee6239 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 16 Feb 2015 17:18:05 +0000 Subject: [PATCH] Update exception messages --- .../omertron/themoviedbapi/TheMovieDbApi.java | 19 +------- .../themoviedbapi/methods/TmdbAccount.java | 3 +- .../methods/TmdbAuthentication.java | 14 ++---- .../methods/TmdbConfiguration.java | 3 +- .../themoviedbapi/methods/TmdbKeywords.java | 6 +-- .../themoviedbapi/methods/TmdbMovies.java | 48 +++++++------------ .../themoviedbapi/tools/PostBody.java | 3 +- 7 files changed, 30 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 3128da369..2fb1b6952 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -19,7 +19,6 @@ */ package com.omertron.themoviedbapi; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.methods.TmdbAccount; @@ -92,7 +91,6 @@ import com.omertron.themoviedbapi.wrapper.WrapperPersonList; import java.io.IOException; import java.net.URL; import java.util.List; -import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.http.impl.client.CloseableHttpClient; import org.slf4j.Logger; @@ -611,21 +609,6 @@ public class TheMovieDbApi { } } - /** - * Use Jackson to convert Map to JSON string. - * - * @param map - * @return - * @throws MovieDbException - */ - public static String convertToJson(Map map) throws MovieDbException { - try { - return MAPPER.writeValueAsString(map); - } catch (JsonProcessingException jpe) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "JSON conversion failed", "", jpe); - } - } - // /** * Get the basic information for an account. You will need to have a valid @@ -1584,7 +1567,9 @@ public class TheMovieDbApi { // // + // + // // // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java index 2516f26f6..cf9bf2b6d 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java @@ -271,8 +271,7 @@ public class TmdbAccount extends AbstractMethod { try { return MAPPER.readValue(webpage, StatusCode.class); } catch (IOException ex) { - LOG.warn("Failed to modify watch list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to modify watch list", url, ex); } } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java index 788d87fc8..f378bc7c1 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java @@ -70,8 +70,7 @@ public class TmdbAuthentication extends AbstractMethod { try { return MAPPER.readValue(webpage, TokenAuthorisation.class); } catch (IOException ex) { - LOG.warn("Failed to get Authorisation Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Failed to get Authorisation Token", url, ex); } } @@ -88,7 +87,6 @@ public class TmdbAuthentication extends AbstractMethod { TmdbParameters parameters = new TmdbParameters(); if (!token.getSuccess()) { - LOG.warn("Session token was not successful!"); throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Authorisation token was not successful!"); } @@ -99,8 +97,7 @@ public class TmdbAuthentication extends AbstractMethod { try { return MAPPER.readValue(webpage, TokenSession.class); } catch (IOException ex) { - LOG.warn("Failed to get Session Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get Session Token", url, ex); } } @@ -119,7 +116,6 @@ public class TmdbAuthentication extends AbstractMethod { TmdbParameters parameters = new TmdbParameters(); if (!token.getSuccess()) { - LOG.warn("Session token was not successful!"); throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Authorisation token was not successful!"); } @@ -133,8 +129,7 @@ public class TmdbAuthentication extends AbstractMethod { try { return MAPPER.readValue(webpage, TokenAuthorisation.class); } catch (IOException ex) { - LOG.warn("Failed to get Session Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get Session Token", url, ex); } } @@ -160,7 +155,6 @@ public class TmdbAuthentication extends AbstractMethod { try { return MAPPER.readValue(webpage, TokenSession.class); } catch (IOException ex) { - LOG.warn("Failed to get Guest Session Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get Guest Session Token", url, ex); } }} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java index 5e6218a5f..81b7f5ce5 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java @@ -119,8 +119,7 @@ public class TmdbConfiguration extends AbstractMethod { results.copyWrapper(wrapper); return results; } catch (IOException ex) { - LOG.warn("Failed to get job list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get job list", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java index 0dfa70df1..7b5ca4e0b 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java @@ -68,8 +68,7 @@ public class TmdbKeywords extends AbstractMethod { try { return MAPPER.readValue(webpage, Keyword.class); } catch (IOException ex) { - LOG.warn("Failed to get keyword: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get keyword " + keywordId, url, ex); } } @@ -98,8 +97,7 @@ public class TmdbKeywords extends AbstractMethod { results.copyWrapper(wrapper); return results; } catch (IOException ex) { - LOG.warn("Failed to get keyword movies: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get keyword movies", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java index 54cd7b9d8..ee6e1d8f9 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java @@ -20,7 +20,6 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; -import static com.omertron.themoviedbapi.TheMovieDbApi.convertToJson; import com.omertron.themoviedbapi.model.AlternativeTitle; import com.omertron.themoviedbapi.model.Artwork; import com.omertron.themoviedbapi.model.Keyword; @@ -38,6 +37,8 @@ import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.PostBody; +import com.omertron.themoviedbapi.tools.PostTools; import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; import com.omertron.themoviedbapi.wrapper.WrapperImages; @@ -51,7 +52,6 @@ import com.omertron.themoviedbapi.wrapper.WrapperTranslations; import com.omertron.themoviedbapi.wrapper.WrapperVideos; import java.io.IOException; import java.net.URL; -import java.util.Collections; import org.yamj.api.common.exception.ApiExceptionType; /** @@ -79,8 +79,7 @@ public class TmdbMovies extends AbstractMethod { * * It will return the single highest rated poster and backdrop. * - * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies - * found. + * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies found. * * @param movieId * @param language @@ -99,7 +98,6 @@ public class TmdbMovies extends AbstractMethod { try { MovieDb movie = MAPPER.readValue(webpage, MovieDb.class); if (movie == null || movie.getId() == 0) { - LOG.warn("No movie found for ID '{}'", movieId); throw new MovieDbException(ApiExceptionType.ID_NOT_FOUND, "No movie found for ID: " + movieId, url); } return movie; @@ -113,8 +111,7 @@ public class TmdbMovies extends AbstractMethod { * * It will return the single highest rated poster and backdrop. * - * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies - * found. + * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies found. * * @param imdbId * @param language @@ -143,8 +140,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method is used to retrieve all of the alternative titles we have for - * a particular movie. + * This method is used to retrieve all of the alternative titles we have for a particular movie. * * @param movieId * @param country @@ -199,8 +195,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method should be used when you’re wanting to retrieve all of the - * images for a particular movie. + * This method should be used when you’re wanting to retrieve all of the images for a particular movie. * * @param movieId * @param language @@ -228,8 +223,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method is used to retrieve all of the keywords that have been added - * to a particular movie. + * This method is used to retrieve all of the keywords that have been added to a particular movie. * * Currently, only English keywords exist. * @@ -257,8 +251,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method is used to retrieve all of the release and certification data - * we have for a specific movie. + * This method is used to retrieve all of the release and certification data we have for a specific movie. * * @param movieId * @param language @@ -286,8 +279,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method is used to retrieve all of the trailers for a particular - * movie. + * This method is used to retrieve all of the trailers for a particular movie. * * Supported sites are YouTube and QuickTime. * @@ -317,8 +309,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method is used to retrieve a list of the available translations for - * a specific movie. + * This method is used to retrieve a list of the available translations for a specific movie. * * @param movieId * @param appendToResponse @@ -344,11 +335,9 @@ public class TmdbMovies extends AbstractMethod { } /** - * The similar movies method will let you retrieve the similar movies for a - * particular movie. + * The similar movies method will let you retrieve the similar movies for a particular movie. * - * This data is created dynamically but with the help of users votes on - * TMDb. + * This data is created dynamically but with the help of users votes on TMDb. * * The data is much better with movies that have more keywords * @@ -480,8 +469,7 @@ public class TmdbMovies extends AbstractMethod { /** * This method is used to retrieve the movies currently in theatres. * - * This is a curated list that will normally contain 100 movies. The default - * response will return 20 movies. + * This is a curated list that will normally contain 100 movies. The default response will return 20 movies. * * TODO: Implement more than 20 movies * @@ -539,8 +527,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method is used to retrieve the top rated movies that have over 10 - * votes on TMDb. + * This method is used to retrieve the top rated movies that have over 10 votes on TMDb. * * The default response will return 20 movies. * @@ -590,7 +577,9 @@ public class TmdbMovies extends AbstractMethod { URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(movieId, MethodSub.RATING).buildUrl(parameters); - String jsonBody = convertToJson(Collections.singletonMap("value", rating)); + String jsonBody = new PostTools() + .add(PostBody.VALUE, rating) + .build(); String webpage = httpTools.postRequest(url, jsonBody); try { @@ -599,8 +588,7 @@ public class TmdbMovies extends AbstractMethod { int code = status.getStatusCode(); return code == POST_SUCCESS_STATUS_CODE; } catch (IOException ex) { - LOG.warn("Failed to post movie rating: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to post movie rating", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/tools/PostBody.java b/src/main/java/com/omertron/themoviedbapi/tools/PostBody.java index f16eb3b5e..e567de720 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/PostBody.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/PostBody.java @@ -31,7 +31,8 @@ public enum PostBody { FAVORITE("favorite"), WATCHLIST("watchlist"), NAME("name"), - DESCRIPTION("description"); + DESCRIPTION("description"), + VALUE("value"); private final String value;