From d1e14541344d428e0b9bbc56693451c5a28b0789 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Sun, 8 Nov 2015 19:42:53 +0000 Subject: [PATCH] Catch connection issues Fixes #28 --- .../themoviedbapi/methods/TmdbEpisodes.java | 18 ++++++++++++------ .../themoviedbapi/tools/HttpTools.java | 4 +++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbEpisodes.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbEpisodes.java index 46e1b2a59..f987c2c1f 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbEpisodes.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbEpisodes.java @@ -64,7 +64,8 @@ public class TmdbEpisodes extends AbstractMethod { } /** - * Get the primary information about a TV episode by combination of a season and episode number. + * Get the primary information about a TV episode by combination of a season + * and episode number. * * @param tvID * @param seasonNumber @@ -106,7 +107,8 @@ public class TmdbEpisodes extends AbstractMethod { } /** - * This method lets users get the status of whether or not the TV episode has been rated. + * This method lets users get the status of whether or not the TV episode + * has been rated. * * A valid session id is required. * @@ -159,7 +161,8 @@ public class TmdbEpisodes extends AbstractMethod { } /** - * Get the external ids for a TV episode by comabination of a season and episode number. + * Get the external ids for a TV episode by comabination of a season and + * episode number. * * @param tvID * @param seasonNumber @@ -186,7 +189,8 @@ public class TmdbEpisodes extends AbstractMethod { } /** - * Get the images (episode stills) for a TV episode by combination of a season and episode number. + * Get the images (episode stills) for a TV episode by combination of a + * season and episode number. * * @param tvID * @param seasonNumber @@ -214,7 +218,8 @@ public class TmdbEpisodes extends AbstractMethod { } /** - * This method lets users rate a TV episode. A valid session id or guest session id is required. + * This method lets users rate a TV episode. A valid session id or guest + * session id is required. * * @param tvID * @param seasonNumber @@ -251,7 +256,8 @@ public class TmdbEpisodes extends AbstractMethod { } /** - * Get the videos that have been added to a TV episode (teasers, clips, etc...) + * Get the videos that have been added to a TV episode (teasers, clips, + * etc...) * * @param tvID * @param seasonNumber diff --git a/src/main/java/com/omertron/themoviedbapi/tools/HttpTools.java b/src/main/java/com/omertron/themoviedbapi/tools/HttpTools.java index 1b3b856ca..b4155cf81 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/HttpTools.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/HttpTools.java @@ -128,7 +128,9 @@ public class HttpTools { * @throws MovieDbException */ private String validateResponse(final DigestedResponse response, final URL url) throws MovieDbException { - if (response.getStatusCode() >= HttpStatus.SC_INTERNAL_SERVER_ERROR) { + if (response.getStatusCode() == 0) { + throw new MovieDbException(ApiExceptionType.CONNECTION_ERROR, response.getContent(), response.getStatusCode(), url, null); + } else if (response.getStatusCode() >= HttpStatus.SC_INTERNAL_SERVER_ERROR) { throw new MovieDbException(ApiExceptionType.HTTP_503_ERROR, response.getContent(), response.getStatusCode(), url, null); } else if (response.getStatusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) { throw new MovieDbException(ApiExceptionType.HTTP_404_ERROR, response.getContent(), response.getStatusCode(), url, null);