Make sure the answer from MAL is successful before updating DB.

This commit is contained in:
inorichi 2015-12-19 20:36:13 +01:00
parent a32c1b5eb2
commit 5f44e5d492
2 changed files with 8 additions and 2 deletions

View File

@ -61,7 +61,12 @@ public class UpdateMangaSyncService extends Service {
MangaSyncService sync = syncManager.getSyncService(mangaSync.sync_id); MangaSyncService sync = syncManager.getSyncService(mangaSync.sync_id);
subscriptions.add(Observable.defer(() -> sync.update(mangaSync)) subscriptions.add(Observable.defer(() -> sync.update(mangaSync))
.flatMap(response -> db.insertMangaSync(mangaSync).createObservable()) .flatMap(response -> {
if (response.isSuccessful()) {
return db.insertMangaSync(mangaSync).createObservable();
}
return Observable.error(new Exception("Could not update MAL"));
})
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {

View File

@ -113,8 +113,9 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
manga.manga_id = this.manga.id; manga.manga_id = this.manga.id;
add(myAnimeList.bind(manga) add(myAnimeList.bind(manga)
.flatMap(response -> { .flatMap(response -> {
if (response.code() == 200 || response.code() == 201) if (response.isSuccessful()) {
return Observable.just(manga); return Observable.just(manga);
}
return Observable.error(new Exception("Could not add manga")); return Observable.error(new Exception("Could not add manga"));
}) })
.flatMap(manga2 -> db.insertMangaSync(manga2).createObservable()) .flatMap(manga2 -> db.insertMangaSync(manga2).createObservable())