minecraft-source/src/com/mojang/realmsclient/client/RealmsError.java

46 lines
1.5 KiB
Java
Raw Normal View History

2020-07-22 06:23:34 +01:00
package com.mojang.realmsclient.client;
import org.apache.logging.log4j.LogManager;
import com.google.gson.JsonObject;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonParser;
import org.apache.logging.log4j.Logger;
public class RealmsError {
private static final Logger LOGGER;
2020-07-22 06:32:50 +01:00
private final String errorMessage;
private final int errorCode;
2020-07-22 06:23:34 +01:00
2020-07-22 06:32:50 +01:00
private RealmsError(final String string, final int integer) {
this.errorMessage = string;
this.errorCode = integer;
}
public static RealmsError create(final String string) {
2020-07-22 06:23:34 +01:00
try {
2020-07-22 06:32:50 +01:00
final JsonParser jsonParser2 = new JsonParser();
final JsonObject jsonObject3 = jsonParser2.parse(string).getAsJsonObject();
final String string2 = JsonUtils.getStringOr("errorMsg", jsonObject3, "");
final int integer5 = JsonUtils.getIntOr("errorCode", jsonObject3, -1);
return new RealmsError(string2, integer5);
2020-07-22 06:23:34 +01:00
}
2020-07-22 06:32:50 +01:00
catch (Exception exception2) {
RealmsError.LOGGER.error("Could not parse RealmsError: " + exception2.getMessage());
2020-07-22 06:23:34 +01:00
RealmsError.LOGGER.error("The error was: " + string);
2020-07-22 06:32:50 +01:00
return new RealmsError("Failed to parse response from server", -1);
2020-07-22 06:23:34 +01:00
}
}
public String getErrorMessage() {
return this.errorMessage;
}
public int getErrorCode() {
return this.errorCode;
}
static {
LOGGER = LogManager.getLogger();
}
}