Add error handling for minute limit
This commit is contained in:
@@ -14,7 +14,8 @@ import java.util.HashSet;
|
||||
|
||||
public class APIFootballUpdater {
|
||||
|
||||
private final String exceededLimitError = "{\"api\":{\"results\":0,\"error\":\"You have reached the request limit for the day\"}}";
|
||||
private final String exceededLimitDayError = "{\"api\":{\"results\":0,\"error\":\"You have reached the request limit for the day\"}}";
|
||||
private final String exceededLimitMinuteError = "{\"api\":{\"results\":0,\"error\":\"Too many requests. Your rate limit is 10 requests per minute.\"}}";
|
||||
private final String wrongEndpointError = "{\"api\":{\"results\":0,\"error\":\"This endpoint does not exist or your parameters are incorrect, contact our support.\"}}";
|
||||
|
||||
public APIFootballUpdater() {
|
||||
@@ -24,7 +25,7 @@ public class APIFootballUpdater {
|
||||
public void updateFixtures(int league) throws Exception {
|
||||
String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin";
|
||||
String content = getRawData(apiFootballUrl);
|
||||
if(!content.equals(this.exceededLimitError)) {
|
||||
if(!content.equals(this.exceededLimitDayError)) {
|
||||
S3Provider prov = new S3Provider();
|
||||
prov.writeFixturesToS3(league, content);
|
||||
}
|
||||
@@ -47,11 +48,9 @@ public class APIFootballUpdater {
|
||||
public void updateRounds(int league) throws Exception {
|
||||
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
|
||||
String content = getRawData(apiFootballUrl);
|
||||
if(!content.equals(this.exceededLimitError)) {
|
||||
S3Provider prov = new S3Provider();
|
||||
prov.writeRoundsToS3(league, content);
|
||||
}
|
||||
}
|
||||
|
||||
public String getRawData(String requestUrl) throws Exception {
|
||||
|
||||
@@ -98,6 +97,12 @@ public class APIFootballUpdater {
|
||||
if (result.toString().equals(wrongEndpointError)) {
|
||||
throw new Exception(requestUrl + " gave error:" + wrongEndpointError);
|
||||
}
|
||||
if (result.toString().equals(exceededLimitDayError)) {
|
||||
throw new Exception(requestUrl + " gave error:" + exceededLimitDayError);
|
||||
}
|
||||
if (result.toString().equals(exceededLimitMinuteError)) {
|
||||
throw new Exception(requestUrl + " gave error:" + exceededLimitMinuteError);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ public class APIFootballUpdaterTest {
|
||||
@Test
|
||||
public void updateFixturesTest() throws Exception {
|
||||
APIFootballUpdater updater = new APIFootballUpdater();
|
||||
updater.updateFixtures(1240);
|
||||
// updater.updateFixtures(1240);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user