Search in sources :

Example 1 with OnCompletedFailedException

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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) RxJavaErrorHandler(rx.plugins.RxJavaErrorHandler) OnCompletedFailedException(rx.exceptions.OnCompletedFailedException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 2 with OnCompletedFailedException

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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) RxJavaErrorHandler(rx.plugins.RxJavaErrorHandler) OnCompletedFailedException(rx.exceptions.OnCompletedFailedException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 3 with OnCompletedFailedException

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));
        }
    }
}
Also used : Response(com.lzy.okgo.model.Response) OnCompletedFailedException(rx.exceptions.OnCompletedFailedException) CompositeException(rx.exceptions.CompositeException) OnErrorNotImplementedException(rx.exceptions.OnErrorNotImplementedException) OnErrorFailedException(rx.exceptions.OnErrorFailedException)

Example 4 with OnCompletedFailedException

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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) RxJavaErrorHandler(rx.plugins.RxJavaErrorHandler) OnCompletedFailedException(rx.exceptions.OnCompletedFailedException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 5 with OnCompletedFailedException

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);
}
Also used : Response(retrofit2.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) RxJavaErrorHandler(rx.plugins.RxJavaErrorHandler) OnCompletedFailedException(rx.exceptions.OnCompletedFailedException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

OnCompletedFailedException (rx.exceptions.OnCompletedFailedException)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 Test (org.junit.Test)4 RxJavaErrorHandler (rx.plugins.RxJavaErrorHandler)4 CompositeException (rx.exceptions.CompositeException)2 OnErrorFailedException (rx.exceptions.OnErrorFailedException)2 OnErrorNotImplementedException (rx.exceptions.OnErrorNotImplementedException)2 Response (com.lzy.okgo.model.Response)1 Response (retrofit2.Response)1