Skip to content

Commit e2b1711

Browse files
committed
wrap doInBackgrond with try/catch
1 parent d9784bf commit e2b1711

File tree

1 file changed

+31
-23
lines changed
  • AndroidSDKCore/src/main/java/com/leanplum/internal

1 file changed

+31
-23
lines changed

AndroidSDKCore/src/main/java/com/leanplum/internal/Request.java

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -235,30 +235,34 @@ private void saveRequestForLater(final Map<String, Object> args) {
235235
LeanplumEventDataManager.executeAsyncTask(new AsyncTask<Void, Void, Void>() {
236236
@Override
237237
protected Void doInBackground(Void... params) {
238-
synchronized (Request.class) {
239-
Context context = Leanplum.getContext();
240-
SharedPreferences preferences = context.getSharedPreferences(
241-
LEANPLUM, Context.MODE_PRIVATE);
242-
SharedPreferences.Editor editor = preferences.edit();
243-
long count = LeanplumEventDataManager.getEventsCount();
244-
String uuid = preferences.getString(Constants.Defaults.UUID_KEY, null);
245-
if (uuid == null || count % MAX_EVENTS_PER_API_CALL == 0) {
246-
uuid = UUID.randomUUID().toString();
247-
editor.putString(Constants.Defaults.UUID_KEY, uuid);
248-
SharedPreferencesUtil.commitChanges(editor);
249-
}
250-
args.put(UUID_KEY, uuid);
251-
LeanplumEventDataManager.insertEvent(JsonConverter.toJson(args));
252-
253-
dataBaseIndex = count;
254-
// Checks if here response and/or error callback for this request. We need to add callbacks to
255-
// eventCallbackManager only if here was internet connection, otherwise triggerErrorCallback
256-
// will handle error callback for this event.
257-
if (response != null || error != null && !Util.isConnected()) {
258-
eventCallbackManager.addCallbacks(currentRequest, response, error);
238+
try {
239+
synchronized (Request.class) {
240+
Context context = Leanplum.getContext();
241+
SharedPreferences preferences = context.getSharedPreferences(
242+
LEANPLUM, Context.MODE_PRIVATE);
243+
SharedPreferences.Editor editor = preferences.edit();
244+
long count = LeanplumEventDataManager.getEventsCount();
245+
String uuid = preferences.getString(Constants.Defaults.UUID_KEY, null);
246+
if (uuid == null || count % MAX_EVENTS_PER_API_CALL == 0) {
247+
uuid = UUID.randomUUID().toString();
248+
editor.putString(Constants.Defaults.UUID_KEY, uuid);
249+
SharedPreferencesUtil.commitChanges(editor);
250+
}
251+
args.put(UUID_KEY, uuid);
252+
LeanplumEventDataManager.insertEvent(JsonConverter.toJson(args));
253+
254+
dataBaseIndex = count;
255+
// Checks if here response and/or error callback for this request. We need to add callbacks to
256+
// eventCallbackManager only if here was internet connection, otherwise triggerErrorCallback
257+
// will handle error callback for this event.
258+
if (response != null || error != null && !Util.isConnected()) {
259+
eventCallbackManager.addCallbacks(currentRequest, response, error);
260+
}
259261
}
260-
return null;
262+
} catch (Throwable t) {
263+
Util.handleException(t);
261264
}
265+
return null;
262266
}
263267
});
264268
}
@@ -466,7 +470,11 @@ private void sendNow() {
466470
Util.executeAsyncTask(true, new AsyncTask<Void, Void, Void>() {
467471
@Override
468472
protected Void doInBackground(Void... params) {
469-
sendRequests();
473+
try {
474+
sendRequests();
475+
} catch (Throwable t) {
476+
Util.handleException(t);
477+
}
470478
return null;
471479
}
472480
});

0 commit comments

Comments
 (0)