[FIX] Ping error handle

This commit is contained in:
Gravita 2023-02-25 19:54:05 +07:00
parent ef5695f679
commit 5c374462ef

View file

@ -1,5 +1,6 @@
package pro.gravit.launcher.client; package pro.gravit.launcher.client;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
@ -162,9 +163,13 @@ private Result modernPing(HInput input, HOutput output) throws IOException {
} }
// Parse JSON response // 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")) { 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(); JsonObject playersObject = object.get("players").getAsJsonObject();
int online = playersObject.get("online").getAsInt(); int online = playersObject.get("online").getAsInt();