Throwing a non-IOException from an OkHttp interceptor cancels a call without an event on the Rx stream
See original GitHub issueIf a non-IOException-derived exception is thrown from an OkHttp interceptor, an RxJava3 call adapter stalls indefinitely and does not signal the exception downstream. (This used to work with the RxJava2 call adapter.)
This is a quick reproducer: https://gist.github.com/realdadfish/c7c0d8cb123c583acd3e683b68afbfa5
The current workaround is to simply make all custom exceptions thrown from within interceptors derive from IOException.
Retrofit: 2.9.0 OkHttp: 4.8.1 RxJava: 3.0.6
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Handle exceptions thrown by a custom okhttp Interceptor in ...
While I was using the Rx implementation, the exception was flawlessly propagated to the onError callback where I was able to handle it...
Read more >Interceptor - OkHttp
For asynchronous calls made with Call.enqueue, an IOException is propagated to the caller indicating that the call was canceled. The interceptor's exception is ......
Read more >OKHttp Error Interceptors, RxJava 2, Repository Pattern, Retrofit
In this tutorial series, I'll be explaining the fundamentals of RESTful Web Services, and what the hell that actually means.
Read more >How to handle RESTful web Services using Retrofit, OkHttp ...
We will use a special OkHttp interceptor class for CoinMarketCap API authentication when making a call to the server.
Read more >A complete guide to OkHttp - LogRocket Blog
OkHttp provides a nice API via Request.Builder to build requests. Synchronous GET. Making a GET request is as easy as this: OkHttpClient client ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Also, I think the real culprit is really
okhttp, look at the implementation ofRealCall.java:and here of the
CallEnqueueObservable.javawhere it exits after it realizes the call is already canceled:@realdadfish
I think this error is not caused by retrofit or OkHttp. I have seen several version OkHttp and Retrofit. They all not catch non-IoException derived exception, Because OkHttp only throw IOException internal. It is cased by RxJava adapter. When use
Retrofit.Builder().addCallAdapterFactory(RxJava3CallAdapterFactory.create())to execute network call. it will callsubscribeActual()function in CallEnqueueObservable. It not catch non-IoException derived exception thrown by OkHttp.You can use
RxJava3CallAdapterFactory.createWithScheduler()orRxJava3CallAdapterFactory.createSynchronous()like this.It will use
CallExecuteObservableto execute http request. It will catch the non-IoException derived exception and call Rxjava downstream’s onError function.