I have encountered the problem, that when the my service is trying to fetch information about the feature flags without having internet connection (potentially can be other cases), your implementation fallbacks to the backup file. Here is the info message:
[io.get.rep.FeatureBackupHandlerFile] (Quarkus Main Thread) Unleash will try to load feature toggle states from temporary backup.
I would like to disable the fallback and get null or an exception if the HTTP request fails. Currently I cannot find a proper way to do that without modifying your implementation, which I want to avoid doing.
Is there a way to disable the fallback to backup file? If not, is there indirect way to do so? For example, check if connection to the API endpoint has failed. You are doing it in HttpFeatureFetcher class by reacting to the exception thrown from HttpURLConnection as following:
@Override
public ClientFeaturesResponse fetchFeatures() throws UnleashException {
HttpURLConnection connection = null;
try {
connection = openConnection(this.toggleUrl);
connection.connect();
return getFeatureResponse(connection, true);
} catch (IOException e) {
throw new UnleashException("Could not fetch toggles", e);
} catch (IllegalStateException e) {
throw new UnleashException(e.getMessage(), e);
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
I tried to use the similar approach, but to properly do it I need access to UnleashConfig at runtime, which I also cannot find a way to access. Currently I can only perform the check as following:
try {
URL url = new URL(unleashUrl.orElse(""));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
int responseCode = connection.getResponseCode();
if(!(responseCode == HttpURLConnection.HTTP_UNAUTHORIZED)){
throw new Exception();
}
return true;
} catch (Exception e) {
logger.error("Error connecting to the API: " + e.getMessage());
return false;
}
But since I do not provide all the information as you do, the response from connection.connect() in my approach either ends up in catch block as there is no internet connection or returns 401 (not authorized). This way I capture the cases when there is no internet connection or API endpoint unavailable. However, everything that can happen after authorization is not taken into account. Configuring the authorized request manually (basically repeating your code) to have more control does not seem feasible.