Retrofit API call receives HTTP FAILED: Canceled

Retrofit API call receives HTTP FAILED: Canceled

Questions : Retrofit API call receives HTTP FAILED: Canceled


Can’t figure out why is this happening. in4codes_okhttp Neither one of rx callbacks (onCompleted(), in4codes_okhttp onError(), onNext()) not gets triggered by in4codes_okhttp my call. The only thing i receive is this in4codes_okhttp okhttp output:

D/OkHttp: --> GET http/1.1 D/OkHttp: --> END GET D/OkHttp: <-- HTTP FAILED: Canceled 

Retrofit module:

@Module public class RestModule { @Provides @Singleton public HttpLoggingInterceptor providesHttpLogginInterceptor() { return new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY); } @Provides @Singleton public OkHttpClient providesOkHttpClient(@NonNull HttpLoggingInterceptor loggingInterceptor) { return new OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .connectTimeout(ConstantsManager.CONNECTION_TIME_OUT, TimeUnit.SECONDS) .readTimeout(ConstantsManager.READ_TIME_OUT, TimeUnit.SECONDS) .build(); } @Provides @Singleton public Gson providesGson() { return new GsonBuilder().create(); } @Provides @Singleton public Retrofit providesRetrofit(@NonNull OkHttpClient okHttpClient, @NonNull Gson gson) { return new Retrofit.Builder() .baseUrl(ConstantsManager.BASE_URL) .client(okHttpClient) .addConverterFactory(SimpleXmlConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson)) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build(); } @Provides @Singleton public PrivatbankApi providesPrivatbankApi(@NonNull Retrofit retrofit) { return retrofit.create(PrivatbankApi.class); } } 

API interface:

public interface PrivatbankApi { @GET Observable<CurrentRates> loadCurrentRates(@NonNull @Url String url); @GET("exchange_rates") Observable<DateRates> loadDateRates(@NonNull @Query("json") Boolean json, @NonNull @Query("date") String date); } 


subscription = dataManager.loadDateRates(date) .subscribeOn( .doAfterTerminate(() -> { }) .subscribe(dateRates -> { // My code here... }, throwable -> { Timber.e(throwable, "Error while loading data occurred!"); }); 

By the way, both of the calls gets the same in4codes_okhttp error:

D/OkHttp: --> GET http/1.1 D/OkHttp: --> END GET D/OkHttp: <-- HTTP FAILED: Canceled D/OkHttp: --> GET http/1.1 D/OkHttp: --> END GET D/OkHttp: <-- HTTP FAILED: Canceled 

Total Answers 5

Answers 1 : of Retrofit API call receives HTTP FAILED: Canceled

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



Answers 2 : of Retrofit API call receives HTTP FAILED: Canceled

Thanks to @Kiskae. This gave me the in4codes_rx-android correct hint. In my case I used a in4codes_rx-android CompositeSubscription and added a in4codes_rx-android subscription to it after it was in4codes_rx-android 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 */ 



Answers 3 : of Retrofit API call receives HTTP FAILED: Canceled

What helped to me is to replace in4codes_rx-android deprecated call adapter:

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


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

This helped me with this issue and I get in4codes_rx-android onError() called every time. More info in4codes_rx-android on this: in4codes_rx-android



Answers 4 : of Retrofit API call receives HTTP FAILED: Canceled

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

My Solution: I only defined two in4codes_rx-android different subscription channels.



Answers 5 : of Retrofit API call receives HTTP FAILED: Canceled

Using Kotlin coroutines I got the same in4codes_rx-android exception. First I closed a ViewModel in4codes_rx-android (and a dialog) and then started a Job in4codes_rx-android with HTTP-request. In this case the in4codes_rx-android coroutine was cancelled: in4codes_rx-android kotlinx.coroutines.JobCancellationException: in4codes_rx-android Job was cancelled; in4codes_rx-android job=SupervisorJobImpl{Cancelling}.

close() modelScope.launch { val response = withContext(Dispatchers.IO) { ... } response?.let { ... } } 

Then I moved closing the ViewModel to in4codes_rx-android the end of the request.


Answer Link
  • Unable to run NoraUI mvn verify goal
  • Unable to run my app on emulator in VS Code
  • Unable to run multiple instances of libVLC(MobileVLCKit) in IOS via flutter framework
  • Unable to run make on griddb source on ubuntu 20.04 (building from source)
  • Unable to run latexindent macOS Monterey 12.0.1
  • Unable to run kotlinc-native command
  • Unable to run JUnit Test… Java.lang.ExceptionInInitializerError (Android Studio)
  • Unable to run java with -Xmx > 966m
  • Unable to run ionic cap run android from wsl2 inorder to start android emulator
  • Unable to run Intel HAXM installer: Cannot start process, the working directory does not exist
  • fs
  • Unable to run Google Analytics sample code
  • unable to run flutter run after upgarding to flutter 2.8.0 from 2.5.3
  • Unable to run Django with PostgreSQL in Docker
  • Unable to Run Container Using testcontainers
  • Unable to run ClojureScript Hello World program, Error building classpath. Error reading edn.
  • unable to run client command for apache karaf 4.3.3 through remote server
  • Unable to run c program 2nd time using eclipse
  • unable to run c++ in visual studio code on m1 chipset
  • Unable to run Android Instrumented Tests
  • Unable to run adb, check your Android SDK installation and ANDROID_SDK_ROOT environment variable: …AndroidSdkplatform-toolsadb.exe
  • Unable to run a singlespecific .spec.ts file through angular cli using ng test –include option
  • Unable to run a Mango query
  • Unable to return response back to view in laravel from package
  • Unable to return object reference in std::optional
  • Unable to return NULL in a function that expects an integer return type
  • Unable to return correct change in JavaScript Cash Register
  • Unable to retrieve version information from Elasticsearch nodes. Request timed out
  • Unable to retrieve values from Axios Response data
  • Unable to retrieve dotenv JWT secret Error: secretOrPrivateKey must have a value
  • Unable to resolve your shell environment
  • Unable to resolve token for FCM while implementing Push notification for Xamarin
  • Unable to resolve the request yii
  • Unable to resolve service for type Swashbuckle.AspNetCore.Swagger.ISwaggerProvider
  • Unable to resolve service for type Microsoft.EntityFrameworkCore.Diagnostics.IDiagnosticsLogger