Add error handling to migrations

This commit is contained in:
inorichi 2018-01-13 11:47:04 +01:00
parent a75457ad88
commit 08f6317beb

View File

@ -85,7 +85,9 @@ class MigrationPresenter(
state = state.copy(isReplacingManga = true) state = state.copy(isReplacingManga = true)
Observable.defer { source.fetchChapterList(manga) } Observable.defer { source.fetchChapterList(manga) }
.onErrorReturn { emptyList() }
.doOnNext { migrateMangaInternal(source, it, prevManga, manga, replace) } .doOnNext { migrateMangaInternal(source, it, prevManga, manga, replace) }
.onErrorReturn { emptyList() }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.doOnUnsubscribe { state = state.copy(isReplacingManga = false) } .doOnUnsubscribe { state = state.copy(isReplacingManga = false) }
@ -98,7 +100,11 @@ class MigrationPresenter(
db.inTransaction { db.inTransaction {
// Update chapters read // Update chapters read
if (preferences.migrateChapters().getOrDefault()) { if (preferences.migrateChapters().getOrDefault()) {
try {
syncChaptersWithSource(db, sourceChapters, manga, source) syncChaptersWithSource(db, sourceChapters, manga, source)
} catch (e: Exception) {
// Worst case, chapters won't be synced
}
val prevMangaChapters = db.getChapters(prevManga).executeAsBlocking() val prevMangaChapters = db.getChapters(prevManga).executeAsBlocking()
val maxChapterRead = prevMangaChapters.filter { it.read } val maxChapterRead = prevMangaChapters.filter { it.read }