I am writing an application that uses RoboSpice. In the request listener onRequestFailure( SpiceException arg0 ) is there a way to know for sure that the error was a result of a
It's even easier than all of the other answers.
For me @Scrotos answer was problematic, because the whole point for the 401 to be caught is to make the request to auth endpoint and then make the primary request again. So that you only return to UI with desired data or some "real" error.
So it shouldn't be done inside the callback, but rather inside loadDataFromNetwork() itself.
I've done it this way:
@Override
public SubscriptionsContainer loadDataFromNetwork() {
//...
ResponseEntity response = null;
try {
response = getRestTemplate().exchange(
//your request data
);
} catch (HttpClientErrorException e) {
HttpStatus statusCode = e.getStatusCode();
//check the exception, if it's 401, make call to auth and repeat loadDataFromNetwork()
}