Merge pull request #22 from ThomasRubini/exceptionally

This commit is contained in:
Thomas Rubini 2022-12-13 19:52:48 +01:00 committed by GitHub
commit 8453331c9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 4 deletions

View File

@ -60,6 +60,11 @@ public CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String pa
),
dependenciesNames
));
}).exceptionally(error ->{
error.printStackTrace();
logger.warning("Error while fetching package %s from the API : \n%s".formatted(packageName, error));
futureResult.complete(null);
return null;
});
return futureResult;

View File

@ -9,6 +9,8 @@ import fr.packageviewer.Pair;
import fr.packageviewer.parser.AsyncRequestsParser;
import org.json.*;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Logger;
import fr.packageviewer.pack.Package;
import fr.packageviewer.pack.SearchedPackage;
import fr.packageviewer.LoggerManager;
@ -17,6 +19,8 @@ import fr.packageviewer.pack.SearchedPackage;
public class FedoraDistribution extends AsyncRequestsParser implements Distribution {
private static final Logger logger = LoggerManager.getLogger("FedoraDistribution");
protected CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String packageName) {
// create a new http client
HttpClient client = HttpClient.newHttpClient();
@ -60,6 +64,11 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
),
dependenciesNames
));
}).exceptionally(error->{
error.printStackTrace();
logger.warning("Error while fetching package %s from the API : \n%s".formatted(packageName, error));
futureResult.complete(null);
return null;
});
// if there's an error, return an empty string
return futureResult;

View File

@ -69,12 +69,12 @@ public abstract class AsyncRequestsParser {
// TODO this doesn't seem clean
logger.fine("Completing callback DEPS for package %s (depth=%s)".formatted(packageName, depth));
futurePackage.complete(pack);
}).exceptionally((e2 -> {
logger.warning("Error while fetching package %s (depth=%s) from the API : \n%s".formatted(packageName, depth, e2));
e2.printStackTrace();
}).exceptionally(error -> {
error.printStackTrace();
logger.warning("Error while manipulating package %s (depth=%s) : \n%s".formatted(packageName, depth, error));
futurePackage.complete(null);
return null;
}));
});
return futurePackage;
}