A
A
Alexey2016-09-15 12:11:54
Android
Alexey, 2016-09-15 12:11:54

How to make a centralized error handler in Retrofit 2?

Google, and the documentation itself on the second retrofit, basically. offers to catch errors by response.isSuccessful() in onResponse in case of errors by HTTP response codes and check for exceptions in onFailure. Yes, it seems to be understandable, but there are 100500+ requests and the idea of ​​​​how to do such checks in each of them gives up. Tell me, if the method of a centralized error handler, as in the case of HTTP codes, and with a network error, etc.? HTTP client OkHttpClient.
Thanks a lot.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mitaichik, 2016-09-15
@mitaichik

Interceptors may help https://github.com/square/okhttp/wiki/Interceptors

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question