Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Issue #8846: Propagate exceptions to error callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalmeida committed Nov 3, 2020
1 parent 3339328 commit 0482d83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,17 @@ internal class AccountObserver(
if (authType != AuthType.Existing && authType != AuthType.Recovered) {
logger.debug("Subscribing for FxaPushScope ($fxaPushScope) events.")

push.subscribe(fxaPushScope) { subscription ->
logger.info("Created a new subscription: $subscription")
CoroutineScope(Dispatchers.Main).launch {
account.deviceConstellation().setDevicePushSubscription(subscription.into())
}
}
push.subscribe(
scope = fxaPushScope,
onSubscribeError = { e ->
logger.info("Re-subscribing to FxA push failed.", e)
},
onSubscribe = { subscription ->
logger.info("Created a new subscription: $subscription")
CoroutineScope(Dispatchers.Main).launch {
account.deviceConstellation().setDevicePushSubscription(subscription.into())
}
})
}

// NB: can we just expose registerDeviceObserver on account manager?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,18 @@ class AutoPushFeature(
*
* @param scope The subscription identifier which usually represents the website's URI.
* @param appServerKey An optional key provided by the application server.
* @param onSubscribeError The callback invoked if the call does not successfully complete.
* @param onSubscribeError The callback invoked with an [Exception] if the call does not successfully complete.
* @param onSubscribe The callback invoked when a subscription for the [scope] is created.
*/
fun subscribe(
scope: String,
appServerKey: String? = null,
onSubscribeError: () -> Unit = {},
onSubscribeError: (Exception) -> Unit = {},
onSubscribe: ((AutoPushSubscription) -> Unit) = {}
) {
connection.ifInitialized {
coroutineScope.launchAndTry(errorBlock = {
onSubscribeError()
coroutineScope.launchAndTry(errorBlock = { exception ->
onSubscribeError(exception)
}, block = {
val sub = subscribe(scope, appServerKey)
onSubscribe(sub)
Expand All @@ -207,24 +207,24 @@ class AutoPushFeature(
* Un-subscribes from a valid subscription and invokes the [onUnsubscribe] callback with the result.
*
* @param scope The subscription identifier which usually represents the website's URI.
* @param onUnsubscribeError The callback invoked if the call does not successfully complete.
* @param onUnsubscribeError The callback invoked with an [Exception] if the call does not successfully complete.
* @param onUnsubscribe The callback invoked when a subscription for the [scope] is removed.
*/
fun unsubscribe(
scope: String,
onUnsubscribeError: () -> Unit = {},
onUnsubscribeError: (Exception) -> Unit = {},
onUnsubscribe: (Boolean) -> Unit = {}
) {
connection.ifInitialized {
coroutineScope.launchAndTry(errorBlock = {
onUnsubscribeError()
coroutineScope.launchAndTry(errorBlock = { exception ->
onUnsubscribeError(exception)
}, block = {
val result = unsubscribe(scope)

if (result) {
onUnsubscribe(result)
} else {
onUnsubscribeError()
onUnsubscribeError(IllegalStateException("Un-subscribing with the native client failed."))
}
})
}
Expand Down

0 comments on commit 0482d83

Please sign in to comment.