@@ -4,6 +4,7 @@ import android.content.Context
44import com.onesignal.IOneSignal
55import com.onesignal.common.IDManager
66import com.onesignal.common.OneSignalUtils
7+ import com.onesignal.common.exceptions.BackendException
78import com.onesignal.common.modeling.ModelChangeTags
89import com.onesignal.common.modules.IModule
910import 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
0 commit comments