use of rx.exceptions.OnErrorFailedException in project retrofit by square.
the class CompletableThrowingSafeSubscriberTest method bodyThrowingInOnErrorDeliveredToPlugin.
@Test
public void bodyThrowingInOnErrorDeliveredToPlugin() {
server.enqueue(new MockResponse().setResponseCode(404));
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (throwable instanceof OnErrorFailedException) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
}
});
RecordingSubscriber<Void> observer = subscriberRule.create();
final RuntimeException e = new RuntimeException();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
service.completable().subscribe(new ForwardingCompletableObserver(observer) {
@Override
public void onError(Throwable throwable) {
errorRef.set(throwable);
throw e;
}
});
CompositeException composite = (CompositeException) pluginRef.get().getCause();
assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
use of rx.exceptions.OnErrorFailedException in project retrofit by square.
the class ObservableThrowingSafeSubscriberTest method responseThrowingInOnErrorDeliveredToPlugin.
@Test
public void responseThrowingInOnErrorDeliveredToPlugin() {
server.enqueue(new MockResponse().setSocketPolicy(DISCONNECT_AFTER_REQUEST));
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (throwable instanceof OnErrorFailedException) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
}
});
RecordingSubscriber<Response<String>> observer = subscriberRule.create();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
final RuntimeException e = new RuntimeException();
service.response().subscribe(new ForwardingSubscriber<Response<String>>(observer) {
@Override
public void onError(Throwable throwable) {
if (!errorRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable);
}
throw e;
}
});
CompositeException composite = (CompositeException) pluginRef.get().getCause();
assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
use of rx.exceptions.OnErrorFailedException 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.OnErrorFailedException in project retrofit by square.
the class ObservableThrowingSafeSubscriberTest method resultThrowingInOnErrorDeliveredToPlugin.
@Test
public void resultThrowingInOnErrorDeliveredToPlugin() {
server.enqueue(new MockResponse());
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (throwable instanceof OnErrorFailedException) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
}
});
RecordingSubscriber<Result<String>> observer = subscriberRule.create();
final RuntimeException first = new RuntimeException();
final RuntimeException second = new RuntimeException();
service.result().subscribe(new ForwardingSubscriber<Result<String>>(observer) {
@Override
public void onNext(Result<String> value) {
// The only way to trigger onError for a result is if onNext throws.
throw first;
}
@Override
public void onError(Throwable throwable) {
throw second;
}
});
CompositeException composite = (CompositeException) pluginRef.get().getCause();
assertThat(composite.getExceptions()).containsExactly(first, second);
}
use of rx.exceptions.OnErrorFailedException in project retrofit by square.
the class ObservableThrowingSafeSubscriberTest method bodyThrowingInOnErrorDeliveredToPlugin.
@Test
public void bodyThrowingInOnErrorDeliveredToPlugin() {
server.enqueue(new MockResponse().setResponseCode(404));
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (throwable instanceof OnErrorFailedException) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
}
});
RecordingSubscriber<String> observer = subscriberRule.create();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
final RuntimeException e = new RuntimeException();
service.body().subscribe(new ForwardingSubscriber<String>(observer) {
@Override
public void onError(Throwable throwable) {
if (!errorRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable);
}
throw e;
}
});
CompositeException composite = (CompositeException) pluginRef.get().getCause();
assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
Aggregations