Update exception messages

master
Stuart Boston 11 years ago
parent 9d396d32e5
commit c3edbc2aad

@ -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<String, ?> map) throws MovieDbException {
try {
return MAPPER.writeValueAsString(map);
} catch (JsonProcessingException jpe) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "JSON conversion failed", "", jpe);
}
}
//<editor-fold defaultstate="collapsed" desc="Account">
/**
* Get the basic information for an account. You will need to have a valid
@ -1584,7 +1567,9 @@ public class TheMovieDbApi {
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="People">
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Reviews">
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Search">

@ -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);
}
}
}

@ -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);
}
}}

@ -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);
}
}

@ -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);
}
}

@ -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 youre wanting to retrieve all of the
* images for a particular movie.
* This method should be used when youre 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);
}
}

@ -31,7 +31,8 @@ public enum PostBody {
FAVORITE("favorite"),
WATCHLIST("watchlist"),
NAME("name"),
DESCRIPTION("description");
DESCRIPTION("description"),
VALUE("value");
private final String value;

Loading…
Cancel
Save