From 50ba1198c74b44b74f6f8ae346df03b45acf6262 Mon Sep 17 00:00:00 2001 From: Julian Arndt Date: Sun, 10 Jan 2021 22:22:49 +0100 Subject: [PATCH] Improve error handling --- .../java/de/jeyp91/apifootball/APIFootballConnector.java | 4 ++-- src/main/java/de/jeyp91/apifootball/APIFootballMatch.java | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/jeyp91/apifootball/APIFootballConnector.java b/src/main/java/de/jeyp91/apifootball/APIFootballConnector.java index adb6b4b..cb94526 100644 --- a/src/main/java/de/jeyp91/apifootball/APIFootballConnector.java +++ b/src/main/java/de/jeyp91/apifootball/APIFootballConnector.java @@ -73,8 +73,8 @@ public class APIFootballConnector { try { APIFootballMatch match = new APIFootballMatch((JSONObject) matchArray.get(i), this.season); matchesList.add(match); - } catch (NullPointerException e) { - logger.error("Could not create config for match: " + matchArray.get(i).toString()); + } catch (Exception e) { + logger.error(e.getMessage()); } } diff --git a/src/main/java/de/jeyp91/apifootball/APIFootballMatch.java b/src/main/java/de/jeyp91/apifootball/APIFootballMatch.java index 3449fad..72816b7 100644 --- a/src/main/java/de/jeyp91/apifootball/APIFootballMatch.java +++ b/src/main/java/de/jeyp91/apifootball/APIFootballMatch.java @@ -12,7 +12,7 @@ public class APIFootballMatch extends BaseMatch { private final String teamNameGuest; private Boolean showTable = null; - public APIFootballMatch(JSONObject json, int season) { + public APIFootballMatch(JSONObject json, int season) throws Exception { this.matchId = Integer.parseInt(json.get("fixture_id").toString()); // TODO this.leagueId = Integer.parseInt(json.get("league_id").toString()); @@ -22,7 +22,11 @@ public class APIFootballMatch extends BaseMatch { this.teamNameGuest = ((JSONObject) json.get("awayTeam")).get("team_name").toString(); this.goalsHome = getNumberOrNull(json.get("goalsHomeTeam")); this.goalsGuest = getNumberOrNull(json.get("goalsAwayTeam")); - this.matchday = getMatchdayFromRoundString(season, json.get("round").toString(), this.leagueId); + try { + this.matchday = getMatchdayFromRoundString(season, json.get("round").toString(), this.leagueId); + } catch (Exception e) { + throw new Exception("Did not find matchday for league '" + this.leagueId + "': '" + json.get("round").toString() + "'"); + } this.matchDatetime = (String) json.get("event_date"); }