Skip to content

Commit

Permalink
sync: harden realm towards null exceptions (fixes open-learning-excha…
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 and dogi authored Sep 18, 2023
1 parent fc31c73 commit e26b096
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1043
versionName "0.10.43"
versionCode 1044
versionName "0.10.44"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import org.ole.planet.myplanet.MainApplication;
Expand Down Expand Up @@ -232,14 +233,21 @@ public void uploadFeedback(final SuccessListener listener) {
try {
Response res;
res = apiInterface.postDoc(Utilities.getHeader(), "application/json", Utilities.getUrl() + "/feedback", RealmFeedback.serializeFeedback(feedback)).execute();
if (res.body() != null) {
Utilities.log(new Gson().toJson(res.body()));
JsonObject r = (JsonObject) res.body();
feedback.set_rev(r.get("rev").getAsString());
feedback.set_id(r.get("id").getAsString());
JsonObject r = (JsonObject) res.body();
if (r != null) {
JsonElement revElement = r.get("rev");
JsonElement idElement = r.get("id");

if (revElement != null && idElement != null) {
feedback.set_rev(revElement.getAsString());
feedback.set_id(idElement.getAsString());
} else {
Utilities.log("Missing 'rev' or 'id' elements in the JSON response");
}
} else {
Utilities.log("ERRRRRRRR " + res.errorBody().string());
}

} catch (IOException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit e26b096

Please sign in to comment.