Fix small bug in Downloader
authorNiki Roo <niki@nikiroo.be>
Mon, 19 Mar 2018 18:05:34 +0000 (19:05 +0100)
committerNiki Roo <niki@nikiroo.be>
Mon, 19 Mar 2018 18:05:34 +0000 (19:05 +0100)
src/be/nikiroo/utils/Downloader.java

index 1b82755067986b20d584c821b0d6c73fca3cf2ad..2919ff01bf551d2d99eca89883c42a1c2e744f51 100644 (file)
@@ -202,11 +202,19 @@ public class Downloader {
                conn.connect();
 
                // Check if redirect
-               if (conn instanceof HttpURLConnection
-                               && ((HttpURLConnection) conn).getResponseCode() / 100 == 3) {
-                       String newUrl = conn.getHeaderField("Location");
-                       return open(new URL(newUrl), originalUrl, currentReferer,
-                                       cookiesValues, postParams, getParams, oauth);
+               if (conn instanceof HttpURLConnection) {
+                       int repCode = 0;
+                       try {
+                               // Can fail in some circumstances
+                               repCode = ((HttpURLConnection) conn).getResponseCode();
+                       } catch (IOException e) {
+                       }
+
+                       if (repCode / 100 == 3) {
+                               String newUrl = conn.getHeaderField("Location");
+                               return open(new URL(newUrl), originalUrl, currentReferer,
+                                               cookiesValues, postParams, getParams, oauth);
+                       }
                }
 
                InputStream in = conn.getInputStream();