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