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

com.autonomouslogic.commons.rxjava3.internal.ErrorWrapFlowableTransformer 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.Flowable;
import io.reactivex.rxjava3.core.FlowableTransformer;
import lombok.RequiredArgsConstructor;
import org.reactivestreams.Publisher;

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy