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 e1ca1552f7 !947
This commit is contained in:
Hans-Christoph Steiner
2021-09-02 22:25:12 +02:00
parent f7eba90cf2
commit d62f0803bd
2 changed files with 11 additions and 11 deletions

View File

@@ -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()
);

View File

@@ -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));
}