Merge pull request #22 from ThomasRubini/exceptionally
This commit is contained in:
commit
8453331c9c
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user