diff options
author | Cow <cow@volloeko.de> | 2021-04-25 20:11:05 +0200 |
---|---|---|
committer | Cow <cow@volloeko.de> | 2021-04-25 20:11:05 +0200 |
commit | b1e45622c2bf1aacdb101d60a5efe7458f126d77 (patch) | |
tree | a032832c6ad84a783e913aa7388a9cc7dd1b9dd2 /src/main/java/de/cowtipper/cowlection | |
parent | efb5a50de5924d0185e80269cccd67da77a337b3 (diff) | |
download | Cowlection-b1e45622c2bf1aacdb101d60a5efe7458f126d77.tar.gz Cowlection-b1e45622c2bf1aacdb101d60a5efe7458f126d77.tar.bz2 Cowlection-b1e45622c2bf1aacdb101d60a5efe7458f126d77.zip |
Improved error message of /m dp during API downtime
Diffstat (limited to 'src/main/java/de/cowtipper/cowlection')
3 files changed, 11 insertions, 1 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java b/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java index b9a0bbb..7673b60 100644 --- a/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java +++ b/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java @@ -28,6 +28,14 @@ public class HySkyBlockStats { private HySkyBlockStats() { } + /** + * ConcurrentHashMaps don't allow null values, so this acts as a null object + */ + public HySkyBlockStats(boolean fakeNullElement) { + success = false; + cause = "Hypixel API down? Check status.hypixel.net"; + } + public boolean isSuccess() { return success; } diff --git a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsPartyListener.java b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsPartyListener.java index 4630a96..9b11940 100644 --- a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsPartyListener.java +++ b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsPartyListener.java @@ -155,7 +155,7 @@ public class DungeonsPartyListener { ApiUtils.fetchSkyBlockStats(partyMember, hySkyBlockStats -> { // (2) once completed, request SkyBlock stats - partyMemberStats.put(partyMemberName, hySkyBlockStats); + partyMemberStats.put(partyMemberName, hySkyBlockStats != null ? hySkyBlockStats : new HySkyBlockStats(true)); if (pendingApiRequests.decrementAndGet() == 0) { // (3) wait for all requests to finish diff --git a/src/main/java/de/cowtipper/cowlection/util/ApiUtils.java b/src/main/java/de/cowtipper/cowlection/util/ApiUtils.java index 584e818..70e4328 100644 --- a/src/main/java/de/cowtipper/cowlection/util/ApiUtils.java +++ b/src/main/java/de/cowtipper/cowlection/util/ApiUtils.java @@ -159,6 +159,8 @@ public class ApiUtils { connection.getResponseCode(); if (connection.getResponseCode() == HttpStatus.SC_NO_CONTENT) { // http status 204 return null; + } else if (connection.getResponseCode() == HttpStatus.SC_BAD_GATEWAY && url.startsWith("https://api.hypixel.net/")) { // http status 502 (cloudflare) + throw new IOException("Couldn't contact Hypixel API (502 Bad Gateway). API might be down, check https://status.hypixel.net for info."); } else { BufferedReader reader; InputStream errorStream = connection.getErrorStream(); |