Skip to content

Commit 950b275

Browse files
authored
Merge pull request #1802 from OneSignal/user_model/remove_throws
User model/remove throws
2 parents ed80fcc + 2a8fc52 commit 950b275

File tree

3 files changed

+50
-32
lines changed

3 files changed

+50
-32
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import com.onesignal.IOneSignal
55
import com.onesignal.common.IDManager
66
import com.onesignal.common.OneSignalUtils
7+
import com.onesignal.common.exceptions.BackendException
78
import com.onesignal.common.modeling.ModelChangeTags
89
import com.onesignal.common.modules.IModule
910
import com.onesignal.common.safeString
@@ -254,7 +255,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
254255
Logging.log(LogLevel.DEBUG, "login(externalId: $externalId, jwtBearerToken: $jwtBearerToken)")
255256

256257
if (!isInitialized) {
257-
throw Exception("Must call 'initWithContext' before use")
258+
Logging.log(LogLevel.ERROR, "Must call 'initWithContext' before using Login")
258259
}
259260

260261
var currentIdentityExternalId: String? = null
@@ -306,28 +307,29 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
306307
)
307308

308309
if (!result) {
309-
throw Exception("Could not login user")
310+
Logging.log(LogLevel.ERROR, "Could not login user")
311+
} else {
312+
// enqueue a RefreshUserOperation to pull the user from the backend and refresh the models.
313+
// This is a separate enqueue operation to ensure any outstanding operations that happened
314+
// after the createAndSwitchToNewUser have been executed, and the retrieval will be the
315+
// most up to date reflection of the user.
316+
_operationRepo!!.enqueueAndWait(
317+
RefreshUserOperation(
318+
_configModel!!.appId,
319+
_identityModelStore!!.model.onesignalId,
320+
),
321+
true,
322+
)
310323
}
311-
312-
// enqueue a RefreshUserOperation to pull the user from the backend and refresh the models.
313-
// This is a separate enqueue operation to ensure any outstanding operations that happened
314-
// after the createAndSwitchToNewUser have been executed, and the retrieval will be the
315-
// most up to date reflection of the user.
316-
_operationRepo!!.enqueueAndWait(
317-
RefreshUserOperation(
318-
_configModel!!.appId,
319-
_identityModelStore!!.model.onesignalId,
320-
),
321-
true,
322-
)
323324
}
324325
}
325326

326327
override fun logout() {
327328
Logging.log(LogLevel.DEBUG, "logout()")
328329

329330
if (!isInitialized) {
330-
throw Exception("Must call 'initWithContext' before use")
331+
Logging.log(LogLevel.ERROR, "Must call 'initWithContext' before using Login")
332+
return
331333
}
332334

333335
// only allow one login/logout at a time

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/UserManager.kt

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ internal open class UserManager(
5050
Logging.log(LogLevel.DEBUG, "setAlias(label: $label, id: $id)")
5151

5252
if (label.isEmpty()) {
53-
throw Exception("Cannot add empty alias")
53+
Logging.log(LogLevel.ERROR, "Cannot add empty alias")
54+
return
5455
}
5556

5657
if (label == IdentityConstants.ONESIGNAL_ID) {
57-
throw Exception("Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias")
58+
Logging.log(LogLevel.ERROR, "Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias")
59+
return
5860
}
5961

6062
_identityModel[label] = id
@@ -65,11 +67,13 @@ internal open class UserManager(
6567

6668
aliases.forEach {
6769
if (it.key.isEmpty()) {
68-
throw Exception("Cannot add empty alias")
70+
Logging.log(LogLevel.ERROR, "Cannot add empty alias")
71+
return
6972
}
7073

7174
if (it.key == IdentityConstants.ONESIGNAL_ID) {
72-
throw Exception("Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias")
75+
Logging.log(LogLevel.ERROR, "Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias")
76+
return
7377
}
7478
}
7579

@@ -82,11 +86,13 @@ internal open class UserManager(
8286
Logging.log(LogLevel.DEBUG, "removeAlias(label: $label)")
8387

8488
if (label.isEmpty()) {
85-
throw Exception("Cannot remove empty alias")
89+
Logging.log(LogLevel.ERROR, "Cannot remove empty alias")
90+
return
8691
}
8792

8893
if (label == IdentityConstants.ONESIGNAL_ID) {
89-
throw Exception("Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias")
94+
Logging.log(LogLevel.ERROR, "Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias")
95+
return
9096
}
9197

9298
_identityModel.remove(label)
@@ -97,11 +103,13 @@ internal open class UserManager(
97103

98104
labels.forEach {
99105
if (it.isEmpty()) {
100-
throw Exception("Cannot remove empty alias")
106+
Logging.log(LogLevel.ERROR, "Cannot remove empty alias")
107+
return
101108
}
102109

103110
if (it == IdentityConstants.ONESIGNAL_ID) {
104-
throw Exception("Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias")
111+
Logging.log(LogLevel.ERROR, "Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias")
112+
return
105113
}
106114
}
107115

@@ -114,7 +122,8 @@ internal open class UserManager(
114122
Logging.log(LogLevel.DEBUG, "addEmail(email: $email)")
115123

116124
if (!OneSignalUtils.isValidEmail(email)) {
117-
throw Exception("Cannot add invalid email address as subscription: $email")
125+
Logging.log(LogLevel.ERROR, "Cannot add invalid email address as subscription: $email")
126+
return
118127
}
119128

120129
_subscriptionManager.addEmailSubscription(email)
@@ -124,7 +133,8 @@ internal open class UserManager(
124133
Logging.log(LogLevel.DEBUG, "removeEmail(email: $email)")
125134

126135
if (!OneSignalUtils.isValidEmail(email)) {
127-
throw Exception("Cannot remove invalid email address as subscription: $email")
136+
Logging.log(LogLevel.ERROR, "Cannot remove invalid email address as subscription: $email")
137+
return
128138
}
129139

130140
_subscriptionManager.removeEmailSubscription(email)
@@ -134,7 +144,8 @@ internal open class UserManager(
134144
Logging.log(LogLevel.DEBUG, "addSms(sms: $sms)")
135145

136146
if (!OneSignalUtils.isValidPhoneNumber(sms)) {
137-
throw Exception("Cannot add invalid sms number as subscription: $sms")
147+
Logging.log(LogLevel.ERROR, "Cannot add invalid sms number as subscription: $sms")
148+
return
138149
}
139150

140151
_subscriptionManager.addSmsSubscription(sms)
@@ -144,7 +155,8 @@ internal open class UserManager(
144155
Logging.log(LogLevel.DEBUG, "removeSms(sms: $sms)")
145156

146157
if (!OneSignalUtils.isValidPhoneNumber(sms)) {
147-
throw Exception("Cannot remove invalid sms number as subscription: $sms")
158+
Logging.log(LogLevel.ERROR, "Cannot remove invalid sms number as subscription: $sms")
159+
return
148160
}
149161

150162
_subscriptionManager.removeSmsSubscription(sms)
@@ -154,7 +166,8 @@ internal open class UserManager(
154166
Logging.log(LogLevel.DEBUG, "setTag(key: $key, value: $value)")
155167

156168
if (key.isEmpty()) {
157-
throw Exception("Cannot add tag with empty key")
169+
Logging.log(LogLevel.ERROR, "Cannot add tag with empty key")
170+
return
158171
}
159172

160173
_propertiesModel.tags[key] = value
@@ -165,7 +178,8 @@ internal open class UserManager(
165178

166179
tags.forEach {
167180
if (it.key.isEmpty()) {
168-
throw Exception("Cannot add tag with empty key")
181+
Logging.log(LogLevel.ERROR, "Cannot add tag with empty key")
182+
return
169183
}
170184
}
171185

@@ -178,7 +192,8 @@ internal open class UserManager(
178192
Logging.log(LogLevel.DEBUG, "removeTag(key: $key)")
179193

180194
if (key.isEmpty()) {
181-
throw Exception("Cannot remove tag with empty key")
195+
Logging.log(LogLevel.ERROR, "Cannot remove tag with empty key")
196+
return
182197
}
183198

184199
_propertiesModel.tags.remove(key)
@@ -189,7 +204,8 @@ internal open class UserManager(
189204

190205
keys.forEach {
191206
if (it.isEmpty()) {
192-
throw Exception("Cannot remove tag with empty key")
207+
Logging.log(LogLevel.ERROR, "Cannot remove tag with empty key")
208+
return
193209
}
194210
}
195211

OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/backend/impl/InAppBackendService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal class InAppBackendService(
4141

4242
override suspend fun getIAMData(appId: String, messageId: String, variantId: String?): GetIAMDataResponse {
4343
val htmlPath = htmlPathForMessage(messageId, variantId, appId)
44-
?: throw Exception("variantId not valid: $variantId")
44+
?: return GetIAMDataResponse(null, false)
4545

4646
val response = _httpClient.get(htmlPath, null)
4747

0 commit comments

Comments
 (0)