From fd0cf634392169f250bb6affcca416769049fb79 Mon Sep 17 00:00:00 2001 From: tom79 Date: Tue, 4 Feb 2020 18:40:28 +0100 Subject: [PATCH] Avoid to lost the composed message when an error occurs --- .../java/app/fedilab/android/activities/TootActivity.java | 1 - app/src/main/java/app/fedilab/android/client/API.java | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/TootActivity.java b/app/src/main/java/app/fedilab/android/activities/TootActivity.java index f3bb34382..c7b806a32 100644 --- a/app/src/main/java/app/fedilab/android/activities/TootActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/TootActivity.java @@ -2683,7 +2683,6 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, showAToast(apiResponse.getError().getError()); return; } - } final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); boolean split_toot = sharedpreferences.getBoolean(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS + userId + instance, false); diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index 4fcdaf405..301a61c3d 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -52,6 +52,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -4719,6 +4720,7 @@ public class API { e.printStackTrace(); } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); + setDefaultError(e); } apiResponse.setStatuses(statuses); return apiResponse; @@ -6469,7 +6471,7 @@ public class API { APIError.setStatusCode(statusCode); String message = statusCode + " - " + error.getMessage(); try { - JSONObject jsonObject = new JSONObject(error.getMessage()); + JSONObject jsonObject = new JSONObject(Objects.requireNonNull(error.getMessage())); String errorM = jsonObject.get("error").toString(); message = "Error " + statusCode + " : " + errorM; } catch (JSONException e) {