Retrofit API call receives “HTTP FAILED: java.io.IOException: Canceled”

前端 未结 4 956
难免孤独
难免孤独 2021-01-01 09:58

Can\'t figure out why is this happening. Neither one of rx callbacks (onCompleted(), onError(), onNext()) not gets triggered by my call. The only thing i receive is this okh

相关标签:
4条回答
  • 2021-01-01 10:10

    Thanks to @Kiskae. This gave me the correct hint. In my case I used a CompositeSubscription and added a subscription to it after it was unsubscribed by another method.

    /**
     * Adds a new {@link Subscription} to this {@code CompositeSubscription} if the
     * {@code CompositeSubscription} is not yet unsubscribed. If the {@code CompositeSubscription} <em>is</em>
     * unsubscribed, {@code add} will indicate this by explicitly unsubscribing the new {@code Subscription} as
     * well.
     *
     * @param s
     *         the {@link Subscription} to add
     */
    
    0 讨论(0)
  • 2021-01-01 10:21

    I had the same problem but in my case when two requests subscribed in the same CompositeDisposable one of them gets cancelled. I mean those 2 requests are done in parallel.

    My Solution: I only defined two different subscription channels.

    0 讨论(0)
  • 2021-01-01 10:31

    That exception gets thrown if the request is cancelled by the user. When using RxJavaCallAdapterFactory this happens if the subscription is unsubscribed before the call can complete. So I guess at some point after you do the call you do subscription.unsubscribe() which cancels the underlying requests.

    0 讨论(0)
  • 2021-01-01 10:32

    What helped to me is to replace deprecated call adapter:

    implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
    

    with:

    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
    

    This helped me with this issue and I get onError() called every time. More info on this: https://github.com/JakeWharton/retrofit2-rxjava2-adapter

    0 讨论(0)
提交回复
热议问题