Java Code Examples for io.reactivex.Observer#onError()

The following examples show how to use io.reactivex.Observer#onError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoinmarketcapTickerService.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {
            observer.onNext(response.body());
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 2
Source File: MaybeConsumers.java    From science-journal with Apache License 2.0 6 votes vote down vote up
/**
 * Allows a function that takes a MaybeConsumer to pipe a single success value to the given
 * Observer (which may also be accepting values from other places)
 *
 * @return a {@link MaybeConsumer<T>} that pipes {@link MaybeConsumer#success(Object)} to {@link
 *     Observer#onNext(Object)}, and {@link MaybeConsumer#fail(Exception)} to {@link
 *     Observer#onError(Throwable)}
 */
public static <T> MaybeConsumer<T> fromObserver(Observer<T> o) {
  return new MaybeConsumer<T>() {
    @Override
    public void success(T value) {
      // if value is null, just report empty
      if (value != null) {
        o.onNext(value);
      }
      o.onComplete();
    }

    @Override
    public void fail(Exception e) {
      o.onError(e);
    }
  };
}
 
Example 3
Source File: TrustWalletTickerService.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {
            observer.onNext(response.body());
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 4
Source File: BlockExplorerClient.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super retrofit2.Response<T>> apply(Observer<? super T> observer) throws Exception {
          return new DisposableObserver<Response<T>>() {
              @Override
              public void onNext(Response<T> response) {
                  observer.onNext(response.body());
                  observer.onComplete();
              }

              @Override
              public void onError(Throwable e) {
                  observer.onError(e);
              }

              @Override
              public void onComplete() {
                  observer.onComplete();
              }
          };
}
 
Example 5
Source File: CoinmarketcapTickerService.java    From ETHWallet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {
            observer.onNext(response.body());
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 6
Source File: BlockExplorerClient.java    From ETHWallet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super retrofit2.Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {
            observer.onNext(response.body());
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 7
Source File: MercuryWalletTickerService.java    From ETHWallet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {
            observer.onNext(response.body());
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 8
Source File: EthplorerTokenService.java    From ETHWallet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Observer<? super Response<EthplorerResponse>> apply(Observer<? super EthplorerResponse> observer) throws Exception {
    return new DisposableObserver<Response<EthplorerResponse>>() {
        @Override
        public void onNext(Response<EthplorerResponse> response) {
            EthplorerResponse body = response.body();
            if (body != null && body.error == null) {
                observer.onNext(body);
                observer.onComplete();
            } else {
                if (body != null) {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(body.error.code, body.error.message)));
                } else {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(UNKNOWN, "Service not available")));
                }
            }
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 9
Source File: EthplorerTokenService.java    From trust-wallet-android-source with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Observer<? super Response<EthplorerResponse>> apply(Observer<? super EthplorerResponse> observer) throws Exception {
    return new DisposableObserver<Response<EthplorerResponse>>() {
        @Override
        public void onNext(Response<EthplorerResponse> response) {
            EthplorerResponse body = response.body();
            if (body != null && body.error == null) {
                observer.onNext(body);
                observer.onComplete();
            } else {
                if (body != null) {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(body.error.code, body.error.message)));
                } else {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(UNKNOWN, "Service not available")));
                }
            }
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 10
Source File: ObserverCircuitBreaker.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> downstream) {
    if (circuitBreaker.tryAcquirePermission()) {
        upstream.subscribe(new CircuitBreakerObserver(downstream));
    } else {
        downstream.onSubscribe(EmptyDisposable.INSTANCE);
        downstream.onError(createCallNotPermittedException(circuitBreaker));
    }
}
 
Example 11
Source File: EthplorerTokenService.java    From Upchain-wallet with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Observer<? super Response<EthplorerResponse>> apply(Observer<? super EthplorerResponse> observer) throws Exception {
    return new DisposableObserver<Response<EthplorerResponse>>() {
        @Override
        public void onNext(Response<EthplorerResponse> response) {
            EthplorerResponse body = response.body();
            if (body != null && body.error == null) {
                observer.onNext(body);
                observer.onComplete();
            } else {
                if (body != null) {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(body.error.code, body.error.message)));
                } else {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(UNKNOWN, "Service not available")));
                }
            }
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 12
Source File: Preconditions.java    From PatternLockView with Apache License 2.0 5 votes vote down vote up
public static boolean checkMainThread(Observer<?> observer) {
    if (Looper.myLooper() != Looper.getMainLooper()) {
        observer.onError(new IllegalStateException(
                "Expected to be called on the main thread but was " + Thread.currentThread().getName()));
        return false;
    }
    return true;
}
 
Example 13
Source File: RxSubscriptionUtil.java    From RxBus2 with Apache License 2.0 5 votes vote down vote up
public static <T> Observer<T> wrapObserver(Observer<T> observer, IRxBusQueue isResumedProvider)
{
    return new Observer<T>()
    {
        @Override
        public void onSubscribe(Disposable d) {
            observer.onSubscribe(d);
        }

        @Override
        public void onComplete()
        {
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e)
        {
            observer.onError(e);
        }

        @Override
        public void onNext(T t)
        {
            if (RxUtil.safetyQueueCheck(t, isResumedProvider))
                observer.onNext(t);
        }
    };
}
 
Example 14
Source File: RxBusUtil.java    From RxBus2 with Apache License 2.0 5 votes vote down vote up
public static <T> Observer<T> wrapObserver(Observer<T> observer, IRxBusQueue isResumedProvider)
{
    return new Observer<T>()
    {
        @Override
        public void onSubscribe(Disposable d) {
            observer.onSubscribe(d);
        }

        @Override
        public void onComplete()
        {
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e)
        {
            observer.onError(e);
        }


        @Override
        public void onNext(T t)
        {
            if (RxUtil.safetyQueueCheck(t, isResumedProvider))
                observer.onNext(t);
        }
    };
}
 
Example 15
Source File: ObserverRateLimiter.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> downstream) {
    long waitDuration = rateLimiter.reservePermission();
    if (waitDuration >= 0) {
        if (waitDuration > 0) {
            Completable.timer(waitDuration, TimeUnit.NANOSECONDS)
                .subscribe(() -> upstream.subscribe(new RateLimiterObserver(downstream)));
        } else {
            upstream.subscribe(new RateLimiterObserver(downstream));
        }
    } else {
        downstream.onSubscribe(EmptyDisposable.INSTANCE);
        downstream.onError(createRequestNotPermitted(rateLimiter));
    }
}
 
Example 16
Source File: Preconditions.java    From Tangram-Android with MIT License 5 votes vote down vote up
public static boolean checkMainThread(Observer<?> observer) {
    if (Looper.myLooper() != Looper.getMainLooper()) {
        observer.onError(new IllegalStateException(
            "Expected to be called on the main thread but was " + Thread.currentThread().getName()));
        return false;
    }
    return true;
}
 
Example 17
Source File: Preconditions.java    From Tangram-Android with MIT License 5 votes vote down vote up
public static boolean checkMainThread(Observer<?> observer) {
    if (Looper.myLooper() != Looper.getMainLooper()) {
        observer.onError(new IllegalStateException(
            "Expected to be called on the main thread but was " + Thread.currentThread().getName()));
        return false;
    }
    return true;
}
 
Example 18
Source File: Preconditions.java    From CameraButton with Apache License 2.0 5 votes vote down vote up
static boolean checkMainThread(Observer<?> observer) {
    if (Looper.myLooper() != Looper.getMainLooper()) {
        observer.onSubscribe(Disposables.empty());
        observer.onError(new IllegalStateException(
                "Expected to be called on the main thread but was " + Thread.currentThread().getName()));
        return false;
    }
    return true;
}
 
Example 19
Source File: CallExecuteObservable.java    From retrocache with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super Response<T>> observer) {
    // Since Call is a one-shot type, clone it for each new observer.
    Call<T> call = mOriginalCall.clone();
    observer.onSubscribe(new CallDisposable(call));

    boolean terminated = false;
    try {
        Response<T> response = getResponse(call);
        if (mCachingActive && !mCachingSystem.contains(CacheUtils.urlToKey(mOriginalCall.request().url()))) {
            mCachingSystem.put(
                    CacheUtils.urlToKey(call.request().url()), CacheUtils.responseToBytes(mRetrofit, response, mResponseType, mAnnotations));
        }
        if (!call.isCanceled()) {
            observer.onNext(response);
        }
        if (!call.isCanceled()) {
            terminated = true;
            observer.onComplete();
        }
    } catch (Throwable t) {
        Exceptions.throwIfFatal(t);
        if (terminated) {
            RxJavaPlugins.onError(t);
        } else if (!call.isCanceled()) {
            try {
                observer.onError(t);
            } catch (Throwable inner) {
                Exceptions.throwIfFatal(inner);
                RxJavaPlugins.onError(new CompositeException(t, inner));
            }
        }
    }
}
 
Example 20
Source File: CallExecuteObservable.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super Response<T>> observer) {
    // Since Call is a one-shot type, clone it for each new observer.
    Call<T> call = originalCall.clone();
    observer.onSubscribe(new CallDisposable(call));

    boolean terminated = false;
    try {
        Response<T> response = call.execute();
        if (!call.isCanceled()) {
            observer.onNext(response);
        }
        if (!call.isCanceled()) {
            terminated = true;
            observer.onComplete();
        }
    } catch (Throwable t) {
        Exceptions.throwIfFatal(t);
        if (terminated) {
            RxJavaPlugins.onError(t);
        } else if (!call.isCanceled()) {
            try {
                observer.onError(t);
            } catch (Throwable inner) {
                Exceptions.throwIfFatal(inner);
                RxJavaPlugins.onError(new CompositeException(t, inner));
            }
        }
    }
}