Add error handling for minute limit

This commit is contained in:
2021-01-06 10:12:47 +01:00
parent 10e6348dcf
commit 341f914b35
2 changed files with 12 additions and 7 deletions

View File

@@ -14,7 +14,8 @@ import java.util.HashSet;
public class APIFootballUpdater { 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.\"}}"; private final String wrongEndpointError = "{\"api\":{\"results\":0,\"error\":\"This endpoint does not exist or your parameters are incorrect, contact our support.\"}}";
public APIFootballUpdater() { public APIFootballUpdater() {
@@ -24,7 +25,7 @@ public class APIFootballUpdater {
public void updateFixtures(int league) throws Exception { public void updateFixtures(int league) throws Exception {
String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin"; String apiFootballUrl = "https://v2.api-football.com/fixtures/league/" + league + "?timezone=Europe/Berlin";
String content = getRawData(apiFootballUrl); String content = getRawData(apiFootballUrl);
if(!content.equals(this.exceededLimitError)) { if(!content.equals(this.exceededLimitDayError)) {
S3Provider prov = new S3Provider(); S3Provider prov = new S3Provider();
prov.writeFixturesToS3(league, content); prov.writeFixturesToS3(league, content);
} }
@@ -47,10 +48,8 @@ public class APIFootballUpdater {
public void updateRounds(int league) throws Exception { public void updateRounds(int league) throws Exception {
String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league; String apiFootballUrl = "https://v2.api-football.com/fixtures/rounds/" + league;
String content = getRawData(apiFootballUrl); String content = getRawData(apiFootballUrl);
if(!content.equals(this.exceededLimitError)) { S3Provider prov = new S3Provider();
S3Provider prov = new S3Provider(); prov.writeRoundsToS3(league, content);
prov.writeRoundsToS3(league, content);
}
} }
public String getRawData(String requestUrl) throws Exception { public String getRawData(String requestUrl) throws Exception {
@@ -98,6 +97,12 @@ public class APIFootballUpdater {
if (result.toString().equals(wrongEndpointError)) { if (result.toString().equals(wrongEndpointError)) {
throw new Exception(requestUrl + " gave error:" + 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(); return result.toString();
} }

View File

@@ -7,7 +7,7 @@ public class APIFootballUpdaterTest {
@Test @Test
public void updateFixturesTest() throws Exception { public void updateFixturesTest() throws Exception {
APIFootballUpdater updater = new APIFootballUpdater(); APIFootballUpdater updater = new APIFootballUpdater();
updater.updateFixtures(1240); // updater.updateFixtures(1240);
} }
@Test @Test