Skip to content

Instantly share code, notes, and snippets.

@grrigore
Last active October 19, 2021 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grrigore/20d3033554a172b54b58cc613acec156 to your computer and use it in GitHub Desktop.
Save grrigore/20d3033554a172b54b58cc613acec156 to your computer and use it in GitHub Desktop.
abstract class TestConsumer : Consumer<Throwable> {
lateinit var onError: () -> Unit
@Throws(Exception::class)
override fun accept(throwable: Throwable?) {
throwable?.let {
if (it is InternetConnectionException) {
onError()
} else {
throw it
}
}
}
}
new TestConsumer() {
@Override
public void accept(Throwable throwable) throws Exception {
super.onError = new Function0<Unit>() {
@Override
public Unit invoke() {
mPubOrderDetailsViewDelegate.onError(throwable.getMessage());
return null;
}
};
super.accept(throwable);
mPubOrderDetailsViewDelegate.hideProgress();
if (throwable instanceof OrderNotFoundException) {
mPubOrderDetailsViewDelegate.onError(mContext.getString(R.string.error_order_not_found, orderId));
} else {
mPubOrderDetailsViewDelegate.onError(throwable.getMessage());
}
throwable.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment