Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve episode sync error handling #711

Merged
merged 3 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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