diff --git a/CHANGELOG.md b/CHANGELOG.md index c5cd60bbdb0..34da4147746 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ * Updates * Update styling of upgrade prompt on account details screen ([#706](https://github.com/Automattic/pocket-casts-android/pull/706)). +* Bug Fixes: + * Improved handling of sync errors + ([#711](https://github.com/Automattic/pocket-casts-android/pull/711)). 7.30 ----- diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/PlaybackManager.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/PlaybackManager.kt index ba31f4909e9..0b4f5af54a5 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/PlaybackManager.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/PlaybackManager.kt @@ -245,7 +245,9 @@ open class PlaybackManager @Inject constructor( syncTimerDisposable = playbackStateRelay.sample(settings.getPeriodicSaveTimeMs(), TimeUnit.MILLISECONDS) .concatMap { if (it.isPlaying && settings.isLoggedIn()) { - syncEpisodeProgress(it).toObservable() + syncEpisodeProgress(it) + .toObservable() + .onErrorResumeNext(Observable.empty()) } else { Observable.empty() } diff --git a/modules/services/servers/src/main/java/au/com/shiftyjelly/pocketcasts/servers/sync/SyncServer.kt b/modules/services/servers/src/main/java/au/com/shiftyjelly/pocketcasts/servers/sync/SyncServer.kt index 5afe5c2204b..c34047b1e48 100644 --- a/modules/services/servers/src/main/java/au/com/shiftyjelly/pocketcasts/servers/sync/SyncServer.kt +++ b/modules/services/servers/src/main/java/au/com/shiftyjelly/pocketcasts/servers/sync/SyncServer.kt @@ -13,6 +13,7 @@ import au.com.shiftyjelly.pocketcasts.servers.sync.login.LoginTokenRequest import au.com.shiftyjelly.pocketcasts.servers.sync.login.LoginTokenResponse import au.com.shiftyjelly.pocketcasts.servers.sync.register.RegisterRequest import au.com.shiftyjelly.pocketcasts.servers.sync.register.RegisterResponse +import io.reactivex.Completable import io.reactivex.Single import okhttp3.RequestBody import retrofit2.Call @@ -76,7 +77,7 @@ interface SyncServer { suspend fun historyYear(@Header("Authorization") authorization: String, @Body request: HistoryYearSyncRequest): HistoryYearResponse @POST("/sync/update_episode") - fun episodeProgressSync(@Header("Authorization") authorization: String, @Body request: EpisodeSyncRequest): Single + fun episodeProgressSync(@Header("Authorization") authorization: String, @Body request: EpisodeSyncRequest): Completable @GET("/subscription/status") fun subscriptionStatus(@Header("Authorization") authorization: String): Single diff --git a/modules/services/servers/src/main/java/au/com/shiftyjelly/pocketcasts/servers/sync/SyncServerManager.kt b/modules/services/servers/src/main/java/au/com/shiftyjelly/pocketcasts/servers/sync/SyncServerManager.kt index 926de4d8466..1121a603442 100644 --- a/modules/services/servers/src/main/java/au/com/shiftyjelly/pocketcasts/servers/sync/SyncServerManager.kt +++ b/modules/services/servers/src/main/java/au/com/shiftyjelly/pocketcasts/servers/sync/SyncServerManager.kt @@ -195,9 +195,9 @@ open class SyncServerManager @Inject constructor( } fun episodeSync(request: EpisodeSyncRequest): Completable { - return getCacheTokenOrLogin { token -> + return getCacheTokenOrLoginCompletable { token -> server.episodeProgressSync(addBearer(token), request) - }.ignoreElement() + } } fun subscriptionStatus(): Single { @@ -351,6 +351,12 @@ open class SyncServerManager @Inject constructor( } } + private fun getCacheTokenOrLoginCompletable(serverCall: (token: String) -> Completable): Completable { + return getCacheTokenOrLogin { token -> + serverCall(token).toSingleDefault(Unit) + }.ignoreElement() + } + private fun getCacheTokenOrLogin(serverCall: (token: String) -> Single): Single { if (settings.isLoggedIn()) { return Single.fromCallable { settings.getSyncToken() ?: throw RuntimeException("Failed to get token") }