Skip to content
Snippets Groups Projects
Commit 646ca355 authored by Volker Richert's avatar Volker Richert
Browse files

fix not resending to NS if upload fails THX @pogman

parent c169a9b3
Branches
Tags
Loading
...@@ -10,6 +10,8 @@ import android.preference.PreferenceManager; ...@@ -10,6 +10,8 @@ import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.util.Log; import android.util.Log;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ResponseHandler; import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
...@@ -169,21 +171,21 @@ public class NightscoutUploadIntentService extends IntentService { ...@@ -169,21 +171,21 @@ public class NightscoutUploadIntentService extends IntentService {
addMbgEntry(entriesBody, record); addMbgEntry(entriesBody, record);
} }
uploadToNightscout(new URL(baseURL + "/entries"), secret, entriesBody); boolean isUploaded = uploadToNightscout(new URL(baseURL + "/entries"), secret, entriesBody);
for(int i = 0; i < devicestatusBody.length(); i++) { for(int i = 0; isUploaded && i < devicestatusBody.length(); i++) {
uploadToNightscout(new URL(baseURL + "/devicestatus"), secret, devicestatusBody.getJSONObject(i)); isUploaded &= uploadToNightscout(new URL(baseURL + "/devicestatus"), secret, devicestatusBody.getJSONObject(i));
} }
if (isUploaded) {
// Yay! We uploaded. Tell Realm // Yay! We uploaded. Tell Realm
// FIXME - check the upload succeeded! // FIXME - check the upload succeeded!
mRealm.beginTransaction(); mRealm.beginTransaction();
for (PumpStatusEvent updateRecord : records) { for (PumpStatusEvent updateRecord : records) {
updateRecord.setUploaded(true); updateRecord.setUploaded(true);
} }
mRealm.commitTransaction(); mRealm.commitTransaction();
}
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Unable to post data", e); Log.e(TAG, "Unable to post data", e);
...@@ -236,6 +238,7 @@ public class NightscoutUploadIntentService extends IntentService { ...@@ -236,6 +238,7 @@ public class NightscoutUploadIntentService extends IntentService {
httpclient.execute(post, responseHandler); httpclient.execute(post, responseHandler);
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Unable to post data to: '" + post.getURI().toString() + "'", e); Log.w(TAG, "Unable to post data to: '" + post.getURI().toString() + "'", e);
return false;
} }
return true; return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment