com.autonomouslogic.commons.rxjava3.internal.ErrorWrapFlowableTransformer Maven / Gradle / Ivy
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