Skip to content

Commit

Permalink
Merge pull request #728 from Adamantcheese/(#720)-thread-deserializat…
Browse files Browse the repository at this point in the history
…ion-issues-handling

(#720) Gracefully handle local thread deserialization exceptions
  • Loading branch information
Adamantcheese authored Feb 25, 2020
2 parents 9b2c0b6 + 72b9191 commit 6c8e4d1
Showing 1 changed file with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.github.adamantcheese.chan.ui.helper.PostHelper;
import com.github.adamantcheese.chan.utils.BackgroundUtils;
import com.github.adamantcheese.chan.utils.Logger;
import com.google.gson.JsonSyntaxException;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -359,7 +360,7 @@ public void onResponse(ChanLoaderResponse response) {

Disposable disposable = Single.fromCallable(() -> onResponseInternal(response))
.subscribeOn(Schedulers.io())
.subscribe(result -> {}, error -> Logger.e(TAG, "onResponse error", error));
.subscribe(result -> { }, error -> Logger.e(TAG, "onResponse error", error));

compositeDisposable.add(disposable);
}
Expand Down Expand Up @@ -577,28 +578,49 @@ public void onErrorResponse(VolleyError error) {
chanThread.isClosed(),
chanThread.isArchived()
);

// We managed to load local thread, do no need to show the error screen
return false;
}
}

// No local thread, show the error screen
return true;
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
if (!result) {
return;
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(showError -> {
if (!showError) {
return;
}

Logger.i(TAG, "Loading error", error);
clearTimer();
ChanLoaderException loaderException = new ChanLoaderException(error);
Logger.i(TAG, "Loading error", error);
notifyAboutError(error);
}, throwable -> {
Logger.i(TAG, "Loading unhandled error", throwable);

for (ChanLoaderCallback l : listeners) {
l.onChanLoaderError(loaderException);
}
});
notifyAboutError(createError(throwable));
});

compositeDisposable.add(disposable);
}

private VolleyError createError(Throwable throwable) {
if (throwable instanceof JsonSyntaxException) {
return new VolleyError("Error while trying to load local thread", throwable);
}

return new VolleyError("Unhandled exception", throwable);
}

private void notifyAboutError(VolleyError error) {
clearTimer();
ChanLoaderException loaderException = new ChanLoaderException(error);

for (ChanLoaderCallback l : listeners) {
l.onChanLoaderError(loaderException);
}
}

/**
* Loads a saved thread if it exists
*/
Expand Down

0 comments on commit 6c8e4d1

Please sign in to comment.