diff --git a/app/src/main/java/eu/faircode/email/ContactInfo.java b/app/src/main/java/eu/faircode/email/ContactInfo.java index 41fc25bdba..b2b276e854 100644 --- a/app/src/main/java/eu/faircode/email/ContactInfo.java +++ b/app/src/main/java/eu/faircode/email/ContactInfo.java @@ -354,7 +354,7 @@ public class ContactInfo { emailGravatar.put(gkey, new Gravatar(false)); } } else - throw new IOException("HTTP status=" + status); + throw new IOException("Error " + status + ": " + urlConnection.getResponseMessage()); } catch (Throwable ex) { Log.w(ex); @@ -907,7 +907,7 @@ public class ContactInfo { try { int status = connection.getResponseCode(); if (status != HttpURLConnection.HTTP_OK) - throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage()); + throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage()); if ("image/svg+xml".equals(type) || url.getPath().endsWith(".svg")) { Bitmap bitmap = ImageHelper.renderSvg(connection.getInputStream(), Color.WHITE, scaleToPixels); diff --git a/app/src/main/java/eu/faircode/email/DisconnectBlacklist.java b/app/src/main/java/eu/faircode/email/DisconnectBlacklist.java index 74cd8bcd09..4f4bf92aba 100644 --- a/app/src/main/java/eu/faircode/email/DisconnectBlacklist.java +++ b/app/src/main/java/eu/faircode/email/DisconnectBlacklist.java @@ -123,7 +123,7 @@ public class DisconnectBlacklist { try { int status = connection.getResponseCode(); if (status != HttpsURLConnection.HTTP_OK) - throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage()); + throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage()); String response = Helper.readStream(connection.getInputStream()); Helper.writeText(file, response); diff --git a/app/src/main/java/eu/faircode/email/EmailProvider.java b/app/src/main/java/eu/faircode/email/EmailProvider.java index dc096335c9..77dbd001e4 100644 --- a/app/src/main/java/eu/faircode/email/EmailProvider.java +++ b/app/src/main/java/eu/faircode/email/EmailProvider.java @@ -391,7 +391,7 @@ public class EmailProvider implements Parcelable { int status = request.getResponseCode(); if (status != HttpURLConnection.HTTP_OK) - throw new FileNotFoundException("Error " + status + ":" + request.getResponseMessage()); + throw new FileNotFoundException("Error " + status + ": " + request.getResponseMessage()); // https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index e1a88570f4..365adc3372 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -8037,7 +8037,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. try { int status = connection.getResponseCode(); if (status != HttpURLConnection.HTTP_OK) - throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage()); + throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage()); Helper.copy(connection.getInputStream(), os); } finally { diff --git a/app/src/main/java/eu/faircode/email/FragmentOAuth.java b/app/src/main/java/eu/faircode/email/FragmentOAuth.java index 3c33b61da3..c110c86d10 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOAuth.java +++ b/app/src/main/java/eu/faircode/email/FragmentOAuth.java @@ -598,7 +598,7 @@ public class FragmentOAuth extends FragmentBase { try { int status = connection.getResponseCode(); if (status != HttpsURLConnection.HTTP_OK) - throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage()); + throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage()); String json = Helper.readStream(connection.getInputStream()); Log.i("json=" + json); diff --git a/app/src/main/java/eu/faircode/email/IPInfo.java b/app/src/main/java/eu/faircode/email/IPInfo.java index ac0b1bb620..fcfd954c09 100644 --- a/app/src/main/java/eu/faircode/email/IPInfo.java +++ b/app/src/main/java/eu/faircode/email/IPInfo.java @@ -82,7 +82,7 @@ public class IPInfo { try { int status = connection.getResponseCode(); if (status != HttpsURLConnection.HTTP_OK) - throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage()); + throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage()); String response = Helper.readStream(connection.getInputStream()); organization.name = response.trim(); diff --git a/app/src/main/java/eu/faircode/email/ImageHelper.java b/app/src/main/java/eu/faircode/email/ImageHelper.java index cb7b15999f..31d1361b03 100644 --- a/app/src/main/java/eu/faircode/email/ImageHelper.java +++ b/app/src/main/java/eu/faircode/email/ImageHelper.java @@ -639,31 +639,36 @@ class ImageHelper { urlConnection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context)); urlConnection.connect(); - int status = urlConnection.getResponseCode(); + try { + int status = urlConnection.getResponseCode(); - if (status == HttpURLConnection.HTTP_MOVED_PERM || - status == HttpURLConnection.HTTP_MOVED_TEMP || - status == HttpURLConnection.HTTP_SEE_OTHER || - status == 307 /* Temporary redirect */ || - status == 308 /* Permanent redirect */) { - if (++redirects > MAX_REDIRECTS) - throw new IOException("Too many redirects"); + if (status == HttpURLConnection.HTTP_MOVED_PERM || + status == HttpURLConnection.HTTP_MOVED_TEMP || + status == HttpURLConnection.HTTP_SEE_OTHER || + status == 307 /* Temporary redirect */ || + status == 308 /* Permanent redirect */) { + if (++redirects > MAX_REDIRECTS) + throw new IOException("Too many redirects"); - String header = urlConnection.getHeaderField("Location"); - if (header == null) - throw new IOException("Location header missing"); + String header = urlConnection.getHeaderField("Location"); + if (header == null) + throw new IOException("Location header missing"); - String location = URLDecoder.decode(header, StandardCharsets.UTF_8.name()); - url = new URL(url, location); - Log.i("Redirect #" + redirects + " to " + url); + String location = URLDecoder.decode(header, StandardCharsets.UTF_8.name()); + url = new URL(url, location); + Log.i("Redirect #" + redirects + " to " + url); + urlConnection.disconnect(); + continue; + } + + if (status != HttpURLConnection.HTTP_OK) + throw new IOException("Error " + status + ": " + urlConnection.getResponseMessage()); + } catch (IOException ex) { urlConnection.disconnect(); - continue; + throw ex; } - if (status != HttpURLConnection.HTTP_OK) - throw new IOException("HTTP status=" + status); - break; }