Skip to content

Commit 7cf7038

Browse files
committed
Don't crash if login fails
1 parent ed80fcc commit 7cf7038

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
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/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)