use of org.infobip.mobile.messaging.mobile.common.exceptions.BackendInvalidParameterException in project mobile-messaging-sdk-android by infobip.
the class UserDataReporter method sync.
public void sync(final MobileMessaging.ResultListener listener, final UserData userData) {
if (userData == null) {
return;
}
mobileMessagingCore.saveUnreportedUserData(userData);
new MRetryableTask<UserData, UserData>() {
@Override
public UserData run(UserData[] userData) {
if (StringUtils.isBlank(mobileMessagingCore.getPushRegistrationId())) {
MobileMessagingLogger.w("Can't report system data without valid registration");
throw InternalSdkError.NO_VALID_REGISTRATION.getException();
}
UserDataReport request = UserDataMapper.toUserDataReport(userData[0].getPredefinedUserData(), userData[0].getCustomUserData());
MobileMessagingLogger.v("USER DATA >>>", request);
UserDataReport response = mobileApiData.reportUserData(userData[0].getExternalUserId(), request);
MobileMessagingLogger.v("USER DATA <<<", response);
return UserDataMapper.fromUserDataReport(userData[0].getExternalUserId(), response.getPredefinedUserData(), response.getCustomUserData());
}
@Override
public void after(UserData userData) {
mobileMessagingCore.setUserDataReported(userData);
broadcaster.userDataReported(userData);
if (listener != null) {
listener.onResult(userData);
}
}
@Override
public void error(Throwable error) {
MobileMessagingLogger.e("MobileMessaging API returned error (user data)! ", error);
mobileMessagingCore.setLastHttpException(error);
stats.reportError(MobileMessagingStatsError.USER_DATA_SYNC_ERROR);
if (error instanceof BackendBaseExceptionWithContent) {
BackendBaseExceptionWithContent errorWithContent = (BackendBaseExceptionWithContent) error;
mobileMessagingCore.setUserDataReported(errorWithContent.getContent(UserData.class));
if (listener != null) {
listener.onError(MobileMessagingError.createFrom(error));
}
} else if (error instanceof BackendInvalidParameterException) {
mobileMessagingCore.setUserDataReportedWithError();
if (listener != null) {
listener.onError(MobileMessagingError.createFrom(error));
}
} else {
MobileMessagingLogger.v("User data synchronization will be postponed to a later time due to communication error");
if (listener != null) {
listener.onResult(UserData.merge(mobileMessagingCore.getUserData(), userData));
}
}
broadcaster.error(MobileMessagingError.createFrom(error));
}
}.retryWith(retryPolicy(listener)).execute(executor, userData);
}
Aggregations