From 5c374462effbdbb83bcb9b8b760649ca83158abc Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sat, 25 Feb 2023 19:54:05 +0700 Subject: [PATCH] [FIX] Ping error handle --- .../java/pro/gravit/launcher/client/ServerPinger.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java index 5cea3f32..57a86dbe 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java @@ -1,5 +1,6 @@ package pro.gravit.launcher.client; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import pro.gravit.launcher.profiles.ClientProfile; @@ -162,9 +163,13 @@ private Result modernPing(HInput input, HOutput output) throws IOException { } // Parse JSON response - JsonObject object = JsonParser.parseString(response).getAsJsonObject(); + JsonElement element = JsonParser.parseString(response); + if(element.isJsonPrimitive()) { + throw new IOException(element.getAsString()); + } + JsonObject object = element.getAsJsonObject(); if (object.has("error")) { - throw new IOException(object.get("error").getAsString()); + throw new IOException(object.get("error").getAsString()); // May be not needed? } JsonObject playersObject = object.get("players").getAsJsonObject(); int online = playersObject.get("online").getAsInt();