Try-catch MojangUtils#getName and a portion of POST /server/heartbeat to make debugging easier

This commit is contained in:
Colin McDonald 2016-06-21 00:58:49 -04:00
parent 27b98d3b69
commit 3bc703384b
2 changed files with 36 additions and 27 deletions

View File

@ -107,6 +107,7 @@ public final class POSTServerHeartbeat implements Handler<RoutingContext> {
if (result.failed()) {
callback.fail(result.cause());
} else {
try {
Map<UUID, User> users = result.result().result(0);
Map<UUID, List<Grant>> grants = result.result().result(1);
Map<UUID, List<Punishment>> punishments = result.result().result(2);
@ -133,6 +134,9 @@ public final class POSTServerHeartbeat implements Handler<RoutingContext> {
}
callback.complete(response);
} catch (Exception ex) {
callback.fail(ex);
}
}
});

View File

@ -4,6 +4,7 @@ import com.mongodb.async.SingleResultCallback;
import lombok.experimental.UtilityClass;
import net.frozenorb.apiv3.APIv3;
import org.bson.Document;
import org.bson.json.JsonParseException;
import java.io.IOException;
import java.util.UUID;
@ -14,6 +15,7 @@ public class MojangUtils {
public static void getName(UUID id, SingleResultCallback<String> callback) {
APIv3.getHttpClient().get("sessionserver.mojang.com", "/session/minecraft/profile/" + id.toString().replace("-", ""), (response) -> {
response.bodyHandler((body) -> {
try {
Document resJson = Document.parse(body.toString());
String name = resJson.getString("name");
@ -22,6 +24,9 @@ public class MojangUtils {
} else {
callback.onResult(name, null);
}
} catch (JsonParseException ex) {
callback.onResult(null, new RuntimeException(body.toString(), ex));
}
});
response.exceptionHandler((error) -> {