Catch zero results for API Football
This commit is contained in:
@@ -119,9 +119,14 @@ public class APIFootballUpdater {
|
|||||||
|
|
||||||
public void checkErrors(String requestUrl, String result) throws Exception {
|
public void checkErrors(String requestUrl, String result) throws Exception {
|
||||||
JSONObject resultObject = stringToJSONObject(result);
|
JSONObject resultObject = stringToJSONObject(result);
|
||||||
if(((JSONObject) resultObject.get("api")).containsKey("error")) {
|
boolean containsError = ((JSONObject) resultObject.get("api")).containsKey("error");
|
||||||
|
int results = Integer.parseInt(((JSONObject) resultObject.get("api")).get("results").toString());
|
||||||
|
if(containsError) {
|
||||||
String errorMessage = ((JSONObject) resultObject.get("api")).get("error").toString();
|
String errorMessage = ((JSONObject) resultObject.get("api")).get("error").toString();
|
||||||
throw new Exception(requestUrl + " returned error: '" + errorMessage + "'");
|
throw new Exception(requestUrl + " returned error: '" + errorMessage + "'");
|
||||||
|
} else if (results == 0) {
|
||||||
|
String statusMessage = ((JSONObject) resultObject.get("api")).get("status").toString();
|
||||||
|
throw new Exception(requestUrl + " did not have any results with status: '" + statusMessage + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user