From d62f0803bdb4e8e1e9e8c0906f9b13e443e53ec8 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 2 Sep 2021 22:25:12 +0200 Subject: [PATCH] make reactivex components actually handle errors doOnError() only runs after an exception, but it then throws it after. This code needs to actually catch the exception move on. onErrorComplete() and onErrorReturnItem() do that. https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators This came from e1ca1552f72f275f32f0f7faa8c428df9ad94b95 !947 --- .../org/fdroid/fdroid/nearby/SwapService.java | 3 ++- .../main/java/org/fdroid/fdroid/Utils.java | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/full/java/org/fdroid/fdroid/nearby/SwapService.java b/app/src/full/java/org/fdroid/fdroid/nearby/SwapService.java index 25ecb4223..63e873df6 100644 --- a/app/src/full/java/org/fdroid/fdroid/nearby/SwapService.java +++ b/app/src/full/java/org/fdroid/fdroid/nearby/SwapService.java @@ -391,11 +391,12 @@ public class SwapService extends Service { }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .doOnError(e -> { + .onErrorComplete(e -> { Intent intent = new Intent(Downloader.ACTION_INTERRUPTED); intent.setData(Uri.parse(repo.address)); intent.putExtra(Downloader.EXTRA_ERROR_MESSAGE, e.getLocalizedMessage()); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent); + return true; }) .subscribe() ); diff --git a/app/src/main/java/org/fdroid/fdroid/Utils.java b/app/src/main/java/org/fdroid/fdroid/Utils.java index 30d9cf3ea..90d0543b7 100644 --- a/app/src/main/java/org/fdroid/fdroid/Utils.java +++ b/app/src/main/java/org/fdroid/fdroid/Utils.java @@ -49,20 +49,12 @@ import android.view.ViewTreeObserver; import android.widget.ImageView; import android.widget.Toast; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.view.DisplayCompat; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.RequestOptions; import com.google.zxing.BarcodeFormat; import com.google.zxing.encode.Contents; import com.google.zxing.encode.QRCodeEncoder; -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.RequestOptions; - import org.fdroid.fdroid.compat.FileCompat; import org.fdroid.fdroid.data.App; import org.fdroid.fdroid.data.Repo; @@ -100,6 +92,12 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.view.DisplayCompat; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; import io.reactivex.rxjava3.core.Single; import io.reactivex.rxjava3.schedulers.Schedulers; @@ -972,6 +970,7 @@ public final class Utils { }) .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) + .onErrorReturnItem(Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)) .doOnError(throwable -> Log.e(TAG, "Could not encode QR as bitmap", throwable)); }