From: Niki Roo Date: Mon, 19 Mar 2018 18:05:34 +0000 (+0100) Subject: Fix small bug in Downloader X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=6149689f27e74830cf2638c8ceffbe0dca9b82f0;p=fanfix-jexer.git Fix small bug in Downloader --- diff --git a/src/be/nikiroo/utils/Downloader.java b/src/be/nikiroo/utils/Downloader.java index 1b82755..2919ff0 100644 --- a/src/be/nikiroo/utils/Downloader.java +++ b/src/be/nikiroo/utils/Downloader.java @@ -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();