Skip to content

Commit

Permalink
Merge pull request #711 from Automattic/fix/episode-sync-error-handling
Browse files Browse the repository at this point in the history
Improve episode sync error handling
  • Loading branch information
geekygecko authored Jan 17, 2023
2 parents 8db6f00 + a330a24 commit c9c5794
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EpisodeSyncResponse>()
.onErrorResumeNext(Observable.empty())
} else {
Observable.empty<EpisodeSyncResponse>()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Void>
fun episodeProgressSync(@Header("Authorization") authorization: String, @Body request: EpisodeSyncRequest): Completable

@GET("/subscription/status")
fun subscriptionStatus(@Header("Authorization") authorization: String): Single<SubscriptionStatusResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubscriptionStatusResponse> {
Expand Down Expand Up @@ -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 <T : Any> getCacheTokenOrLogin(serverCall: (token: String) -> Single<T>): Single<T> {
if (settings.isLoggedIn()) {
return Single.fromCallable { settings.getSyncToken() ?: throw RuntimeException("Failed to get token") }
Expand Down

0 comments on commit c9c5794

Please sign in to comment.