Improve error handling
This commit is contained in:
@@ -18,7 +18,7 @@ public class App {
|
||||
private static int season;
|
||||
private static int league;
|
||||
private static String configFile;
|
||||
private static Logger logger = LogManager.getLogger(App.class);
|
||||
private static final Logger logger = LogManager.getLogger(App.class);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
initOptions(args);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import com.google.api.client.util.DateTime;
|
||||
import de.jeyp91.App;
|
||||
import de.jeyp91.TeamIDMatcher;
|
||||
import de.jeyp91.apifootball.APIFootballMatch;
|
||||
import de.jeyp91.apifootball.APIFootballMatchesProvider;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -13,11 +16,12 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
private static Logger logger = LogManager.getLogger(App.class);
|
||||
|
||||
ArrayList<TLWMatch> tlwMatchesOriginal;
|
||||
ArrayList<TLWMatch> tlwMatchesUpdated;
|
||||
|
||||
public TLWMatchesUpdaterFootball(int season, int league, String configFileName) throws Exception {
|
||||
public TLWMatchesUpdaterFootball(int season, int league, String configFileName) {
|
||||
|
||||
this.season = season;
|
||||
this.league = league;
|
||||
@@ -29,7 +33,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
this.initUpdates();
|
||||
}
|
||||
|
||||
private void initUpdates() throws Exception {
|
||||
private void initUpdates() {
|
||||
|
||||
APIFootballMatchesProvider apiFootballMatchesProvider = new APIFootballMatchesProvider(this.season);
|
||||
TippligaSQLConnector tippligaSQLConnector = new TippligaSQLConnector();
|
||||
@@ -44,7 +48,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
for (TLWMatch match : tlwMatchesOriginalMatchday) tlwMatchesUpdatedMatchday.add(new TLWMatch(match));
|
||||
|
||||
if (apiFootballMatches.size() > tlwMatchesUpdatedMatchday.size()) {
|
||||
throw new Exception("Not matching config!");
|
||||
logger.error("Not matching config!");
|
||||
}
|
||||
|
||||
addMissingMatches(tlwMatchesUpdatedMatchday, apiFootballMatches);
|
||||
@@ -105,7 +109,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
}
|
||||
|
||||
private void addMissingMatches(ArrayList<TLWMatch> tlwMatches,
|
||||
ArrayList<APIFootballMatch> apiFootballMatches) throws Exception {
|
||||
ArrayList<APIFootballMatch> apiFootballMatches) {
|
||||
|
||||
ArrayList<APIFootballMatch> missingMatches = new ArrayList<>();
|
||||
|
||||
@@ -125,14 +129,14 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
}
|
||||
}
|
||||
if(!done) {
|
||||
throw new Exception("Could not add missing match");
|
||||
logger.error("Could not add missing match");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMatchDateTimes(
|
||||
ArrayList<TLWMatch> tlwMatches,
|
||||
ArrayList<APIFootballMatch> apiFootballMatches) throws Exception
|
||||
ArrayList<APIFootballMatch> apiFootballMatches)
|
||||
{
|
||||
for(APIFootballMatch apiFootballMatch : apiFootballMatches) {
|
||||
TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatches);
|
||||
@@ -155,7 +159,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
}
|
||||
}
|
||||
|
||||
private TLWMatch getMatchingMatch(APIFootballMatch apiFootballMatch, ArrayList<TLWMatch> tlwMatches) throws Exception {
|
||||
private TLWMatch getMatchingMatch(APIFootballMatch apiFootballMatch, ArrayList<TLWMatch> tlwMatches) {
|
||||
int foundMatches = 0;
|
||||
TLWMatch matchingMatch = null;
|
||||
for(TLWMatch match : tlwMatches) {
|
||||
@@ -170,7 +174,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
|
||||
}
|
||||
}
|
||||
if(foundMatches > 1) {
|
||||
throw new Exception("Found more than one matching matches");
|
||||
logger.error("Found more than one matching matches");
|
||||
}
|
||||
return matchingMatch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user