From 5f44e5d4920a2d836445536a25ab4386f1258b43 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 19 Dec 2015 20:36:13 +0100 Subject: [PATCH] Make sure the answer from MAL is successful before updating DB. --- .../kanade/mangafeed/data/sync/UpdateMangaSyncService.java | 7 ++++++- .../ui/manga/myanimelist/MyAnimeListPresenter.java | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/sync/UpdateMangaSyncService.java b/app/src/main/java/eu/kanade/mangafeed/data/sync/UpdateMangaSyncService.java index 4733ee4290..0f2ce8ee27 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/sync/UpdateMangaSyncService.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/sync/UpdateMangaSyncService.java @@ -61,7 +61,12 @@ public class UpdateMangaSyncService extends Service { MangaSyncService sync = syncManager.getSyncService(mangaSync.sync_id); 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()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/myanimelist/MyAnimeListPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/myanimelist/MyAnimeListPresenter.java index 85a481e27c..79d6a7a553 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/myanimelist/MyAnimeListPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/myanimelist/MyAnimeListPresenter.java @@ -113,8 +113,9 @@ public class MyAnimeListPresenter extends BasePresenter { manga.manga_id = this.manga.id; add(myAnimeList.bind(manga) .flatMap(response -> { - if (response.code() == 200 || response.code() == 201) + if (response.isSuccessful()) { return Observable.just(manga); + } return Observable.error(new Exception("Could not add manga")); }) .flatMap(manga2 -> db.insertMangaSync(manga2).createObservable())