Search in sources :

Example 6 with CompositeException

use of io.reactivex.exceptions.CompositeException in project retrofit by square.

the class FlowableThrowingTest method bodyThrowingInOnErrorDeliveredToPlugin.

@Test
public void bodyThrowingInOnErrorDeliveredToPlugin() {
    server.enqueue(new MockResponse().setResponseCode(404));
    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });
    RecordingSubscriber<String> subscriber = subscriberRule.create();
    final AtomicReference<Throwable> errorRef = new AtomicReference<>();
    final RuntimeException e = new RuntimeException();
    service.body().subscribe(new ForwardingSubscriber<String>(subscriber) {

        @Override
        public void onError(Throwable throwable) {
            if (!errorRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
            throw e;
        }
    });
    // noinspection ThrowableResultOfMethodCallIgnored
    CompositeException composite = (CompositeException) throwableRef.get();
    assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) CompositeException(io.reactivex.exceptions.CompositeException) AtomicReference(java.util.concurrent.atomic.AtomicReference) CompositeException(io.reactivex.exceptions.CompositeException) Test(org.junit.Test)

Example 7 with CompositeException

use of io.reactivex.exceptions.CompositeException in project retrofit by square.

the class MaybeThrowingTest method bodyThrowingInOnErrorDeliveredToPlugin.

@Test
public void bodyThrowingInOnErrorDeliveredToPlugin() {
    server.enqueue(new MockResponse().setResponseCode(404));
    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });
    RecordingMaybeObserver<String> observer = subscriberRule.create();
    final AtomicReference<Throwable> errorRef = new AtomicReference<>();
    final RuntimeException e = new RuntimeException();
    service.body().subscribe(new ForwardingObserver<String>(observer) {

        @Override
        public void onError(Throwable throwable) {
            if (!errorRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
            throw e;
        }
    });
    // noinspection ThrowableResultOfMethodCallIgnored
    CompositeException composite = (CompositeException) throwableRef.get();
    assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) CompositeException(io.reactivex.exceptions.CompositeException) AtomicReference(java.util.concurrent.atomic.AtomicReference) CompositeException(io.reactivex.exceptions.CompositeException) Test(org.junit.Test)

Example 8 with CompositeException

use of io.reactivex.exceptions.CompositeException in project retrofit by square.

the class SingleThrowingTest method bodyThrowingInOnErrorDeliveredToPlugin.

@Test
public void bodyThrowingInOnErrorDeliveredToPlugin() {
    server.enqueue(new MockResponse().setResponseCode(404));
    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });
    RecordingSingleObserver<String> observer = subscriberRule.create();
    final AtomicReference<Throwable> errorRef = new AtomicReference<>();
    final RuntimeException e = new RuntimeException();
    service.body().subscribe(new ForwardingObserver<String>(observer) {

        @Override
        public void onError(Throwable throwable) {
            if (!errorRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
            throw e;
        }
    });
    // noinspection ThrowableResultOfMethodCallIgnored
    CompositeException composite = (CompositeException) throwableRef.get();
    assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) CompositeException(io.reactivex.exceptions.CompositeException) AtomicReference(java.util.concurrent.atomic.AtomicReference) CompositeException(io.reactivex.exceptions.CompositeException) Test(org.junit.Test)

Example 9 with CompositeException

use of io.reactivex.exceptions.CompositeException in project retrofit by square.

the class SingleThrowingTest method resultThrowingInOnErrorDeliveredToPlugin.

@Ignore("Single's contract is onNext|onError so we have no way of triggering this case")
@Test
public void resultThrowingInOnErrorDeliveredToPlugin() {
    server.enqueue(new MockResponse());
    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });
    RecordingSingleObserver<Result<String>> observer = subscriberRule.create();
    final RuntimeException first = new RuntimeException();
    final RuntimeException second = new RuntimeException();
    service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {

        @Override
        public void onSuccess(Result<String> value) {
            // The only way to trigger onError for Result is if onSuccess throws.
            throw first;
        }

        @Override
        public void onError(Throwable throwable) {
            throw second;
        }
    });
    // noinspection ThrowableResultOfMethodCallIgnored
    CompositeException composite = (CompositeException) throwableRef.get();
    assertThat(composite.getExceptions()).containsExactly(first, second);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) CompositeException(io.reactivex.exceptions.CompositeException) AtomicReference(java.util.concurrent.atomic.AtomicReference) CompositeException(io.reactivex.exceptions.CompositeException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with CompositeException

use of io.reactivex.exceptions.CompositeException in project RxDownload by ssseasonnn.

the class DownloadHelper method logError.

private void logError(Throwable throwable) {
    if (throwable instanceof CompositeException) {
        CompositeException realException = (CompositeException) throwable;
        List<Throwable> exceptions = realException.getExceptions();
        for (Throwable each : exceptions) {
            log(each);
        }
    } else {
        log(throwable);
    }
}
Also used : CompositeException(io.reactivex.exceptions.CompositeException)

Aggregations

CompositeException (io.reactivex.exceptions.CompositeException)21 Test (org.junit.Test)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 MockResponse (okhttp3.mockwebserver.MockResponse)14 Response (retrofit2.Response)4 Ignore (org.junit.Ignore)2 ParseException (android.net.ParseException)1 JsonParseException (com.google.gson.JsonParseException)1 JsonSerializer (com.google.gson.JsonSerializer)1 Single (io.reactivex.Single)1 TestObserver (io.reactivex.observers.TestObserver)1 RxCacheException (io.rx_cache2.RxCacheException)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 Runner (io.vertx.example.util.Runner)1 AbstractVerticle (io.vertx.reactivex.core.AbstractVerticle)1 JDBCClient (io.vertx.reactivex.ext.jdbc.JDBCClient)1 IOException (java.io.IOException)1 NotSerializableException (java.io.NotSerializableException)1 ConnectException (java.net.ConnectException)1