diff --git a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt index d9dd78555f..0b7cec5a31 100644 --- a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt +++ b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt @@ -4,6 +4,7 @@ import android.content.Context import com.onesignal.IOneSignal import com.onesignal.common.IDManager import com.onesignal.common.OneSignalUtils +import com.onesignal.common.exceptions.BackendException import com.onesignal.common.modeling.ModelChangeTags import com.onesignal.common.modules.IModule import com.onesignal.common.safeString @@ -254,7 +255,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider { Logging.log(LogLevel.DEBUG, "login(externalId: $externalId, jwtBearerToken: $jwtBearerToken)") if (!isInitialized) { - throw Exception("Must call 'initWithContext' before use") + Logging.log(LogLevel.ERROR, "Must call 'initWithContext' before using Login") } var currentIdentityExternalId: String? = null @@ -306,20 +307,20 @@ internal class OneSignalImp : IOneSignal, IServiceProvider { ) if (!result) { - throw Exception("Could not login user") + Logging.log(LogLevel.ERROR, "Could not login user") + } else { + // enqueue a RefreshUserOperation to pull the user from the backend and refresh the models. + // This is a separate enqueue operation to ensure any outstanding operations that happened + // after the createAndSwitchToNewUser have been executed, and the retrieval will be the + // most up to date reflection of the user. + _operationRepo!!.enqueueAndWait( + RefreshUserOperation( + _configModel!!.appId, + _identityModelStore!!.model.onesignalId, + ), + true, + ) } - - // enqueue a RefreshUserOperation to pull the user from the backend and refresh the models. - // This is a separate enqueue operation to ensure any outstanding operations that happened - // after the createAndSwitchToNewUser have been executed, and the retrieval will be the - // most up to date reflection of the user. - _operationRepo!!.enqueueAndWait( - RefreshUserOperation( - _configModel!!.appId, - _identityModelStore!!.model.onesignalId, - ), - true, - ) } } @@ -327,7 +328,8 @@ internal class OneSignalImp : IOneSignal, IServiceProvider { Logging.log(LogLevel.DEBUG, "logout()") if (!isInitialized) { - throw Exception("Must call 'initWithContext' before use") + Logging.log(LogLevel.ERROR, "Must call 'initWithContext' before using Login") + return } // only allow one login/logout at a time diff --git a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/UserManager.kt b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/UserManager.kt index c731947c57..28ac15aaa1 100644 --- a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/UserManager.kt +++ b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/UserManager.kt @@ -50,11 +50,13 @@ internal open class UserManager( Logging.log(LogLevel.DEBUG, "setAlias(label: $label, id: $id)") if (label.isEmpty()) { - throw Exception("Cannot add empty alias") + Logging.log(LogLevel.ERROR, "Cannot add empty alias") + return } if (label == IdentityConstants.ONESIGNAL_ID) { - throw Exception("Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias") + Logging.log(LogLevel.ERROR, "Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias") + return } _identityModel[label] = id @@ -65,11 +67,13 @@ internal open class UserManager( aliases.forEach { if (it.key.isEmpty()) { - throw Exception("Cannot add empty alias") + Logging.log(LogLevel.ERROR, "Cannot add empty alias") + return } if (it.key == IdentityConstants.ONESIGNAL_ID) { - throw Exception("Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias") + Logging.log(LogLevel.ERROR, "Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias") + return } } @@ -82,11 +86,13 @@ internal open class UserManager( Logging.log(LogLevel.DEBUG, "removeAlias(label: $label)") if (label.isEmpty()) { - throw Exception("Cannot remove empty alias") + Logging.log(LogLevel.ERROR, "Cannot remove empty alias") + return } if (label == IdentityConstants.ONESIGNAL_ID) { - throw Exception("Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias") + Logging.log(LogLevel.ERROR, "Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias") + return } _identityModel.remove(label) @@ -97,11 +103,13 @@ internal open class UserManager( labels.forEach { if (it.isEmpty()) { - throw Exception("Cannot remove empty alias") + Logging.log(LogLevel.ERROR, "Cannot remove empty alias") + return } if (it == IdentityConstants.ONESIGNAL_ID) { - throw Exception("Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias") + Logging.log(LogLevel.ERROR, "Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias") + return } } @@ -114,7 +122,8 @@ internal open class UserManager( Logging.log(LogLevel.DEBUG, "addEmail(email: $email)") if (!OneSignalUtils.isValidEmail(email)) { - throw Exception("Cannot add invalid email address as subscription: $email") + Logging.log(LogLevel.ERROR, "Cannot add invalid email address as subscription: $email") + return } _subscriptionManager.addEmailSubscription(email) @@ -124,7 +133,8 @@ internal open class UserManager( Logging.log(LogLevel.DEBUG, "removeEmail(email: $email)") if (!OneSignalUtils.isValidEmail(email)) { - throw Exception("Cannot remove invalid email address as subscription: $email") + Logging.log(LogLevel.ERROR, "Cannot remove invalid email address as subscription: $email") + return } _subscriptionManager.removeEmailSubscription(email) @@ -134,7 +144,8 @@ internal open class UserManager( Logging.log(LogLevel.DEBUG, "addSms(sms: $sms)") if (!OneSignalUtils.isValidPhoneNumber(sms)) { - throw Exception("Cannot add invalid sms number as subscription: $sms") + Logging.log(LogLevel.ERROR, "Cannot add invalid sms number as subscription: $sms") + return } _subscriptionManager.addSmsSubscription(sms) @@ -144,7 +155,8 @@ internal open class UserManager( Logging.log(LogLevel.DEBUG, "removeSms(sms: $sms)") if (!OneSignalUtils.isValidPhoneNumber(sms)) { - throw Exception("Cannot remove invalid sms number as subscription: $sms") + Logging.log(LogLevel.ERROR, "Cannot remove invalid sms number as subscription: $sms") + return } _subscriptionManager.removeSmsSubscription(sms) @@ -154,7 +166,8 @@ internal open class UserManager( Logging.log(LogLevel.DEBUG, "setTag(key: $key, value: $value)") if (key.isEmpty()) { - throw Exception("Cannot add tag with empty key") + Logging.log(LogLevel.ERROR, "Cannot add tag with empty key") + return } _propertiesModel.tags[key] = value @@ -165,7 +178,8 @@ internal open class UserManager( tags.forEach { if (it.key.isEmpty()) { - throw Exception("Cannot add tag with empty key") + Logging.log(LogLevel.ERROR, "Cannot add tag with empty key") + return } } @@ -178,7 +192,8 @@ internal open class UserManager( Logging.log(LogLevel.DEBUG, "removeTag(key: $key)") if (key.isEmpty()) { - throw Exception("Cannot remove tag with empty key") + Logging.log(LogLevel.ERROR, "Cannot remove tag with empty key") + return } _propertiesModel.tags.remove(key) @@ -189,7 +204,8 @@ internal open class UserManager( keys.forEach { if (it.isEmpty()) { - throw Exception("Cannot remove tag with empty key") + Logging.log(LogLevel.ERROR, "Cannot remove tag with empty key") + return } } diff --git a/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/backend/impl/InAppBackendService.kt b/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/backend/impl/InAppBackendService.kt index 3f84f7488e..19ada10644 100644 --- a/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/backend/impl/InAppBackendService.kt +++ b/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/backend/impl/InAppBackendService.kt @@ -41,7 +41,7 @@ internal class InAppBackendService( override suspend fun getIAMData(appId: String, messageId: String, variantId: String?): GetIAMDataResponse { val htmlPath = htmlPathForMessage(messageId, variantId, appId) - ?: throw Exception("variantId not valid: $variantId") + ?: return GetIAMDataResponse(null, false) val response = _httpClient.get(htmlPath, null)