All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.autonomouslogic.commons.rxjava3.internal.ErrorWrapObservableTransformer Maven / Gradle / Ivy

There is a newer version: 1.9.2
Show newest version
package com.autonomouslogic.commons.rxjava3.internal;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableSource;
import io.reactivex.rxjava3.core.ObservableTransformer;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public final class ErrorWrapObservableTransformer implements ObservableTransformer {
	private final String message;
	private final ObservableTransformer transformer;
	private boolean upstreamError = false;

	@Override
	public @NonNull ObservableSource apply(@NonNull Observable upstream) {
		return upstream.doOnError(e -> upstreamError = true)
				.compose(transformer)
				.onErrorResumeNext(e -> {
					if (!upstreamError) {
						return Observable.error(new RuntimeException(message, e));
					}
					return Observable.error(e);
				});
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy