aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorbowser0000 <bowser0000@gmail.com>2020-08-29 16:06:45 -0400
committerbowser0000 <bowser0000@gmail.com>2020-08-29 16:06:45 -0400
commit968037478801709042497c409f06aed6c70949b0 (patch)
tree99bf82d1fbcae3449e8d991aba8359111f929185 /src/main
parentaafc6802b16f7f5b92f7ebcfaff263781f6f9546 (diff)
downloadSkyblockMod-968037478801709042497c409f06aed6c70949b0.tar.gz
SkyblockMod-968037478801709042497c409f06aed6c70949b0.tar.bz2
SkyblockMod-968037478801709042497c409f06aed6c70949b0.zip
Add better Hypixel API error messages
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/me/Danker/handlers/APIHandler.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/java/me/Danker/handlers/APIHandler.java b/src/main/java/me/Danker/handlers/APIHandler.java
index 783ca92..34a73ff 100644
--- a/src/main/java/me/Danker/handlers/APIHandler.java
+++ b/src/main/java/me/Danker/handlers/APIHandler.java
@@ -2,10 +2,12 @@ package me.Danker.handlers;
import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Scanner;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
@@ -41,6 +43,17 @@ public class APIHandler {
return object;
} else {
+ if (urlString.startsWith("https://api.hypixel.net/")) {
+ InputStream errorStream = conn.getErrorStream();
+ try (Scanner scanner = new Scanner(errorStream)) {
+ scanner.useDelimiter("\\Z");
+ String error = scanner.next();
+
+ Gson gson = new Gson();
+ JsonObject object = gson.fromJson(error, JsonObject.class);
+ return object;
+ }
+ }
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Request failed. HTTP Error Code: " + conn.getResponseCode()));
}
} catch (MalformedURLException ex) {