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
|
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;
|
return futureResult;
|
||||||
|
|||||||
@ -9,6 +9,8 @@ import fr.packageviewer.Pair;
|
|||||||
import fr.packageviewer.parser.AsyncRequestsParser;
|
import fr.packageviewer.parser.AsyncRequestsParser;
|
||||||
import org.json.*;
|
import org.json.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import fr.packageviewer.pack.Package;
|
import fr.packageviewer.pack.Package;
|
||||||
import fr.packageviewer.pack.SearchedPackage;
|
import fr.packageviewer.pack.SearchedPackage;
|
||||||
import fr.packageviewer.LoggerManager;
|
import fr.packageviewer.LoggerManager;
|
||||||
@ -17,6 +19,8 @@ import fr.packageviewer.pack.SearchedPackage;
|
|||||||
|
|
||||||
public class FedoraDistribution extends AsyncRequestsParser implements Distribution {
|
public class FedoraDistribution extends AsyncRequestsParser implements Distribution {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerManager.getLogger("FedoraDistribution");
|
||||||
|
|
||||||
protected CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String packageName) {
|
protected CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String packageName) {
|
||||||
// create a new http client
|
// create a new http client
|
||||||
HttpClient client = HttpClient.newHttpClient();
|
HttpClient client = HttpClient.newHttpClient();
|
||||||
@ -60,6 +64,11 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
|
|||||||
),
|
),
|
||||||
dependenciesNames
|
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
|
// if there's an error, return an empty string
|
||||||
return futureResult;
|
return futureResult;
|
||||||
|
|||||||
@ -69,12 +69,12 @@ public abstract class AsyncRequestsParser {
|
|||||||
// TODO this doesn't seem clean
|
// TODO this doesn't seem clean
|
||||||
logger.fine("Completing callback DEPS for package %s (depth=%s)".formatted(packageName, depth));
|
logger.fine("Completing callback DEPS for package %s (depth=%s)".formatted(packageName, depth));
|
||||||
futurePackage.complete(pack);
|
futurePackage.complete(pack);
|
||||||
}).exceptionally((e2 -> {
|
}).exceptionally(error -> {
|
||||||
logger.warning("Error while fetching package %s (depth=%s) from the API : \n%s".formatted(packageName, depth, e2));
|
error.printStackTrace();
|
||||||
e2.printStackTrace();
|
logger.warning("Error while manipulating package %s (depth=%s) : \n%s".formatted(packageName, depth, error));
|
||||||
futurePackage.complete(null);
|
futurePackage.complete(null);
|
||||||
return null;
|
return null;
|
||||||
}));
|
});
|
||||||
|
|
||||||
return futurePackage;
|
return futurePackage;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user