Browse Source

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

inorichi 9 năm trước cách đây
mục cha
commit
5f44e5d492

+ 6 - 1
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 -> {

+ 2 - 1
app/src/main/java/eu/kanade/mangafeed/ui/manga/myanimelist/MyAnimeListPresenter.java

@@ -113,8 +113,9 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
         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())