Add error handling everywhere

This commit is contained in:
2021-01-10 21:34:27 +01:00
parent a6145eed64
commit b100e4e2e8
6 changed files with 79 additions and 63 deletions

View File

@@ -2,10 +2,13 @@ package de.jeyp91.apifootball;
import de.jeyp91.ResourceProvider;
import de.jeyp91.S3Provider;
import de.jeyp91.teamidmatcher.TeamIDMatcher;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -15,36 +18,46 @@ import java.util.HashSet;
public class APIFootballUpdater {
private static final Logger logger = LogManager.getLogger(APIFootballUpdater.class);
public APIFootballUpdater() {
}
public void updateFixtures(int league) throws Exception {
public void updateFixtures(int league) {
String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin";
String content = getRawData(apiFootballUrl);
S3Provider prov = new S3Provider();
prov.writeFixturesToS3(league, content);
try {
String content = getRawData(apiFootballUrl);
S3Provider prov = new S3Provider();
prov.writeFixturesToS3(league, content);
} catch (Exception e) {
logger.error(e.getMessage());
}
}
public void updateAllFixtures() throws Exception {
public void updateAllFixtures() {
HashSet<Integer> leagues = getLeagues();
for (Integer league : leagues) {
updateFixtures(league);
}
}
public void updateAllRounds() throws Exception {
public void updateAllRounds() {
HashSet<Integer> leagues = getLeagues();
for (Integer league : leagues) {
updateRounds(league);
}
}
public void updateRounds(int league) throws Exception {
public void updateRounds(int league) {
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
String content = getRawData(apiFootballUrl);
S3Provider prov = new S3Provider();
prov.writeRoundsToS3(league, content);
try {
String content = getRawData(apiFootballUrl);
S3Provider prov = new S3Provider();
prov.writeRoundsToS3(league, content);
} catch (Exception e) {
logger.error(e.getMessage());
}
}
public String getRawData(String requestUrl) throws Exception {