From b1e45622c2bf1aacdb101d60a5efe7458f126d77 Mon Sep 17 00:00:00 2001 From: Cow Date: Sun, 25 Apr 2021 20:11:05 +0200 Subject: Improved error message of /m dp during API downtime --- src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java | 8 ++++++++ .../cowlection/listener/skyblock/DungeonsPartyListener.java | 2 +- src/main/java/de/cowtipper/cowlection/util/ApiUtils.java | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/main/java/de/cowtipper/cowlection') 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(); -- cgit