Skip to content

Commit

Permalink
Clean up code after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Emirlol committed Jul 1, 2024
1 parent 3856ba8 commit 411a62d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 7 additions & 12 deletions src/main/java/de/hysky/skyblocker/utils/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ public static InputStream downloadContent(String url) throws IOException, Interr
.build();

HttpResponse<InputStream> response = HTTP_CLIENT.send(request, BodyHandlers.ofInputStream());
InputStream decodedInputStream = getDecodedInputStream(response);

return decodedInputStream;
return getDecodedInputStream(response);
}

public static String sendGetRequest(String url) throws IOException, InterruptedException {
Expand Down Expand Up @@ -125,16 +124,12 @@ private static InputStream getDecodedInputStream(HttpResponse<InputStream> respo
String encoding = getContentEncoding(response.headers());

try {
switch (encoding) {
case "":
return response.body();
case "gzip":
return new GZIPInputStream(response.body());
case "deflate":
return new InflaterInputStream(response.body());
default:
throw new UnsupportedOperationException("The server sent content in an unexpected encoding: " + encoding);
}
return switch (encoding) {
case "" -> response.body();
case "gzip" -> new GZIPInputStream(response.body());
case "deflate" -> new InflaterInputStream(response.body());
default -> throw new UnsupportedOperationException("The server sent content in an unexpected encoding: " + encoding);
};
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/hysky/skyblocker/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ private static void scheduleMayorTick() {
private static void tickMayorCache() {
CompletableFuture.supplyAsync(() -> {
try {
Http.ApiResponse response = Http.sendCacheableGetRequest("https://api.hypixel.net/v2/resources/skyblock/election");
Http.ApiResponse response = Http.sendCacheableGetRequest("https://api.hypixel.net/v2/resources/skyblock/election", null); //Authentication is not required for this endpoint
if (!response.ok()) throw new HttpResponseException(response.statusCode(), response.content());
JsonObject json = JsonParser.parseString(response.content()).getAsJsonObject();
if (!json.get("success").getAsBoolean()) throw new RuntimeException("Request failed!"); //Can't find a more appropriate exception to throw here.
Expand Down

0 comments on commit 411a62d

Please sign in to comment.