try {
makeApiRequest(user);
} catch (ApiException e) {
for (ApiError error : e.getErrors()) {
if (error instanceof AuthenticationError) {
AuthenticationError authError = (AuthenticationError) error;
if (authError.getReason() == AuthenticationErrorReason.INVALID_EMAIL) {
// Try to regenerate auth token here again in case it expired.
user.setAuthToken(authToken.getAuthToken());
makeApiRequest(user);
} else {
System.err.println("Service call failed for authentication reason: "
+ authError.getReason());
}
}
}
}
}