Throw an exception if there is a bad connection
master
Stuart Boston 12 years ago
parent 421084737c
commit 021daccadc

@ -20,11 +20,11 @@
package com.omertron.themoviedbapi.tools; package com.omertron.themoviedbapi.tools;
import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.MovieDbException;
import org.apache.commons.codec.binary.Base64; import java.io.BufferedReader;
import org.slf4j.Logger; import java.io.IOException;
import org.slf4j.LoggerFactory; import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.*; import java.io.StringWriter;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
@ -36,7 +36,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Web browser with simple cookies support * Web browser with simple cookies support
@ -122,6 +125,11 @@ public final class WebBrowser {
try { try {
cnx = (HttpURLConnection) openProxiedConnection(url); cnx = (HttpURLConnection) openProxiedConnection(url);
// If we get a null connection, then throw an exception
if (cnx == null) {
throw new MovieDbException(MovieDbException.MovieDbExceptionType.CONNECTION_ERROR, "No HTTP connection could be made.");
}
if (isDeleteRequest) { if (isDeleteRequest) {
cnx.setDoOutput(true); cnx.setDoOutput(true);
cnx.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); cnx.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

Loading…
Cancel
Save