package retrofit2.adapter.rxjava2; import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.CompositeException; import io.reactivex.exceptions.Exceptions; import io.reactivex.plugins.RxJavaPlugins; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; /* loaded from: classes2.dex */ final class CallEnqueueObservable extends Observable> { private final Call originalCall; private static final class CallCallback implements Disposable, Callback { private final Call call; private final Observer> observer; boolean terminated = false; CallCallback(Call call, Observer> observer) { this.call = call; this.observer = observer; } @Override // io.reactivex.disposables.Disposable public void dispose() { this.call.cancel(); } public boolean isDisposed() { return this.call.isCanceled(); } @Override // retrofit2.Callback public void onFailure(Call call, Throwable th) { if (call.isCanceled()) { return; } try { this.observer.onError(th); } catch (Throwable th2) { Exceptions.b(th2); RxJavaPlugins.b(new CompositeException(th, th2)); } } @Override // retrofit2.Callback public void onResponse(Call call, Response response) { if (call.isCanceled()) { return; } try { this.observer.onNext(response); if (call.isCanceled()) { return; } this.terminated = true; this.observer.onComplete(); } catch (Throwable th) { if (this.terminated) { RxJavaPlugins.b(th); return; } if (call.isCanceled()) { return; } try { this.observer.onError(th); } catch (Throwable th2) { Exceptions.b(th2); RxJavaPlugins.b(new CompositeException(th, th2)); } } } } CallEnqueueObservable(Call call) { this.originalCall = call; } @Override // io.reactivex.Observable protected void subscribeActual(Observer> observer) { Call clone = this.originalCall.clone(); CallCallback callCallback = new CallCallback(clone, observer); observer.onSubscribe(callCallback); clone.enqueue(callCallback); } }