Skip to content

Commit

Permalink
Issue mozilla-mobile#8846: Propagate exceptions to error callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalmeida committed Nov 17, 2020
1 parent d6ceaba commit f482878
Showing 1 changed file with 9 additions and 9 deletions.
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 f482878

Please sign in to comment.