use of rx.exceptions.OnCompletedFailedException in project retrofit by square.
the class CompletableThrowingSafeSubscriberTest method throwingInOnCompleteDeliveredToPlugin.
@Test
public void throwingInOnCompleteDeliveredToPlugin() {
server.enqueue(new MockResponse());
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (throwable instanceof OnCompletedFailedException) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
}
});
RecordingSubscriber<Void> observer = subscriberRule.create();
final RuntimeException e = new RuntimeException();
service.completable().subscribe(new ForwardingCompletableObserver(observer) {
@Override
public void onCompleted() {
throw e;
}
});
assertThat(pluginRef.get().getCause()).isSameAs(e);
}
use of rx.exceptions.OnCompletedFailedException in project retrofit by square.
the class ObservableThrowingSafeSubscriberTest method resultThrowingInOnCompletedDeliveredToPlugin.
@Test
public void resultThrowingInOnCompletedDeliveredToPlugin() {
server.enqueue(new MockResponse());
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (throwable instanceof OnCompletedFailedException) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
}
});
RecordingSubscriber<Result<String>> observer = subscriberRule.create();
final RuntimeException e = new RuntimeException();
service.result().subscribe(new ForwardingSubscriber<Result<String>>(observer) {
@Override
public void onCompleted() {
throw e;
}
});
observer.assertAnyValue();
assertThat(pluginRef.get().getCause()).isSameAs(e);
}
use of rx.exceptions.OnCompletedFailedException in project okhttp-OkGo by jeasonlzy.
the class CallArbiter method emitResponse.
private void emitResponse(List<Response<T>> responseList) {
try {
synchronized (this) {
Iterator<Response<T>> iterator = responseList.iterator();
while (iterator.hasNext()) {
Response<T> next = iterator.next();
iterator.remove();
if (!isUnsubscribed()) {
subscriber.onNext(next);
} else {
return;
}
}
}
} catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) {
RxJavaHooks.getOnError().call(e);
} catch (Throwable t) {
Exceptions.throwIfFatal(t);
try {
subscriber.onError(t);
} catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) {
RxJavaHooks.getOnError().call(e);
} catch (Throwable inner) {
Exceptions.throwIfFatal(inner);
RxJavaHooks.getOnError().call(new CompositeException(t, inner));
}
}
}
use of rx.exceptions.OnCompletedFailedException in project retrofit by square.
the class ObservableThrowingSafeSubscriberTest method bodyThrowingInOnCompleteDeliveredToPlugin.
@Test
public void bodyThrowingInOnCompleteDeliveredToPlugin() {
server.enqueue(new MockResponse());
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (throwable instanceof OnCompletedFailedException) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
}
});
RecordingSubscriber<String> observer = subscriberRule.create();
final RuntimeException e = new RuntimeException();
service.body().subscribe(new ForwardingSubscriber<String>(observer) {
@Override
public void onCompleted() {
throw e;
}
});
observer.assertAnyValue();
assertThat(pluginRef.get().getCause()).isSameAs(e);
}
use of rx.exceptions.OnCompletedFailedException in project retrofit by square.
the class ObservableThrowingSafeSubscriberTest method responseThrowingInOnCompleteDeliveredToPlugin.
@Test
public void responseThrowingInOnCompleteDeliveredToPlugin() {
server.enqueue(new MockResponse());
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (throwable instanceof OnCompletedFailedException) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
}
});
RecordingSubscriber<Response<String>> observer = subscriberRule.create();
final RuntimeException e = new RuntimeException();
service.response().subscribe(new ForwardingSubscriber<Response<String>>(observer) {
@Override
public void onCompleted() {
throw e;
}
});
observer.assertAnyValue();
assertThat(pluginRef.get().getCause()).isSameAs(e);
}
Aggregations