Now we use the modification as follows:
service.executeSomeRequest(UserPreferenceRequest userPreferenceRequest, new Callback<UserPreferenceResponse>() { @Override public void success(UserPreferenceResponse responseCallback, Response response) { if (responseCallback.getStatus() == ResponseStatus.OK) {
But we have many requests, and almost every request that we implement requires us to write the same error code processing (for API and server errors) that duplicates the code.
We want to redefine only the methods of interest to us, and if the implementation has not been implemented, then the default implementation is executed.
Something like that:
service.executeSomeRequest(UserPreferenceRequest userPreferenceRequest, new CustomCallback<UserPreferenceResponse>() { @Override public void success(UserPreferenceResponse responseCallback, Response response) { super.success(responseCallback, response);
CustomCallback will take care of the API and server errors, and if everything is in order, then only pass the result of the calling activity.
When building the RestAdapter there is setRequestInterceptor(); , which allows me to catch the request before its release, I was thinking about something similar, for example, setResponseInterceptor() , which will allow me to catch the answer before passing it in activity and treating common errors there, but did not find something like that.
android retrofit
Andy res
source share