diff --git a/app/src/main/java/eu/faircode/email/CloudSync.java b/app/src/main/java/eu/faircode/email/CloudSync.java index b20b81a0ee..1d33b350fc 100644 --- a/app/src/main/java/eu/faircode/email/CloudSync.java +++ b/app/src/main/java/eu/faircode/email/CloudSync.java @@ -661,16 +661,26 @@ public class CloudSync { if (status != HttpsURLConnection.HTTP_OK) { String error = "Error " + status + ": " + connection.getResponseMessage(); String detail = Helper.readStream(connection.getErrorStream()); + String msg = "Cloud error=" + error + " detail=" + detail; - Log.e(msg); EntityLog.log(context, EntityLog.Type.Cloud, msg); - JSONObject jerror = new JSONObject(detail); + + JSONObject jerror; + try { + jerror = new JSONObject(detail); + } catch (Throwable ex) { + Log.e(ex); + jerror = new JSONObject(); + } + if (status == HttpsURLConnection.HTTP_FORBIDDEN) throw new SecurityException(jerror.optString("error")); else if (status == HttpsURLConnection.HTTP_PAYMENT_REQUIRED) throw new OperationCanceledException(jerror.optString("error")); - else + else { + Log.e(msg); throw new IOException(error + " " + jerror); + } } String response = Helper.readStream(connection.getInputStream());