Non-IOException subtypes thrown from interceptor never notify Callback
See original GitHub issueA programming error in an interceptor or in OkHttp or an error of any kind will bypass the Callback
and crash the Dispatcher
thread leaving your consumer hanging forever. This was reported to Retrofit’s Kotlin coroutine support, but is not specific to it.
My proposal is for adding something like
default void onFailure(Call call, Throwable t) {
if (t instanceof IOException) {
onFailure(call, (IOException) t);
}
}
and deprecating the existing onFailure
callback in a 3.14.3 or 3.15 and the equivalent added to 4.0. This will force Retrofit onto Java 8, although given the added safety I think that’s acceptable.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:11
- Comments:15 (11 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 >ProducerInterceptor (kafka 0.10.2.1 API)
A plugin interface that allows you to intercept (and possibly mutate) the records received by the producer before they are published to the...
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 FreeTop 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
Top GitHub Comments
+1000 😃 Tried a few times to ask for something allowing handling of non IOException errors and always rejected. Currently using added interceptor for that …
Typical use on Android would be security issues for rooted user who by default block Internet permission, not crashing and having the exception allows to properly notify the user.
I was thinking more like a pluggable handling for the
catch(Throwable)
part with a default implementation.I also liked it more.
the default implementation could just rethrow and an external catch would do exactly what it does now.
as an alternative you could add a new interface and just check for it and use it if available.
I don’t think there’s a clean way to make this kind of change in an API without breaking backward compatibility or requiring an extra step.