Skip to content

Commit 3219c25

Browse files
Added empty alert response support
It was a wrong decision to throw an exception for this situation, because it's *expected* + it happens 99.99% of the time - which caused #onFailedRequest spam.
1 parent 6ef3b3a commit 3219c25

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/main/java/dte/tzevaadomapi/alertsource/AlertSource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
public interface AlertSource
77
{
88
Alert getMostRecentAlert() throws Exception;
9+
10+
11+
public static final Alert EMPTY_RESPONSE = null;
912
}

src/main/java/dte/tzevaadomapi/alertsource/json/JSONAlertSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Alert getMostRecentAlert() throws Exception
3131
JSONArray alertsJsonArray = requestAlertsJSON();
3232

3333
if(alertsJsonArray == null || alertsJsonArray.isEmpty())
34-
throw new IllegalArgumentException("Cannot get the most recent alert due to an empty JSON response!");
34+
return EMPTY_RESPONSE;
3535

3636
return fromJSON((JSONObject) alertsJsonArray.get(0));
3737
}

src/main/java/dte/tzevaadomapi/notifier/TzevaAdomNotifier.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ public CompletableFuture<Void> listen()
5656
{
5757
Alert alert = getMostRecentAlert();
5858

59-
//if the last alert in history doesn't equal to the last requested one - It's TZEVA ADOM
59+
//ignore empty responses
60+
if(alert == AlertSource.EMPTY_RESPONSE)
61+
continue;
62+
63+
//if the last alert in history equals the the last requested - it's not Tzeva Adom
6064
if(lastTzevaAdom.equals(alert))
6165
continue;
6266

0 commit comments

Comments
 (0)