1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 04:35:57 +00:00

Cloud sync: improved error handling

This commit is contained in:
M66B 2023-01-24 11:38:32 +01:00
parent 557426c019
commit edffe78add

View file

@ -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());