Skip to content

Commit

Permalink
Add more detailed error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 committed Dec 21, 2024
1 parent 5b5220b commit 12244a2
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import de.hysky.skyblocker.skyblock.profileviewer.inventory.InventoryPage;
import de.hysky.skyblocker.skyblock.profileviewer.skills.SkillsPage;
import de.hysky.skyblocker.skyblock.profileviewer.slayers.SlayersPage;
import de.hysky.skyblocker.utils.ApiAuthentication;
import de.hysky.skyblocker.utils.ApiUtils;
import de.hysky.skyblocker.utils.Http;
import de.hysky.skyblocker.utils.ProfileUtils;
Expand Down Expand Up @@ -61,6 +62,7 @@ public class ProfileViewerScreen extends Screen {
private JsonObject hypixelProfile;
private JsonObject playerProfile;
private boolean profileNotFound = false;
private String errorMessage = "No Profile";

private int activePage = 0;
private static final String[] PAGE_NAMES = {"Skills", "Slayers", "Dungeons", "Inventories", "Collections"};
Expand Down Expand Up @@ -121,7 +123,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
profileViewerPages[activePage].markWidgetsAsVisible();
profileViewerPages[activePage].render(context, mouseX, mouseY, delta, rootX + 93, rootY + 7);
} else {
context.drawText(textRenderer, profileNotFound ? "No Profile" : "Loading...", rootX + 180, rootY + 80, Color.WHITE.getRGB(), true);
context.drawCenteredTextWithShadow(textRenderer, profileNotFound ? errorMessage : "Loading...", rootX + 200, rootY + 80, Color.WHITE.getRGB());
}
}

Expand All @@ -144,6 +146,7 @@ private CompletableFuture<Void> fetchPlayerData(String username) {
this.playerProfile = hypixelProfile.getAsJsonObject("members").get(ApiUtils.name2Uuid(username)).getAsJsonObject();
}
} catch (Exception e) {
this.errorMessage = ApiAuthentication.getToken() == null ? "Invalid Skyblocker token" : "Skyblock profile not found";
this.profileNotFound = true;
LOGGER.warn("[Skyblocker Profile Viewer] Error while looking for profile", e);
}
Expand All @@ -153,7 +156,8 @@ private CompletableFuture<Void> fetchPlayerData(String username) {
String stringifiedUuid = ApiUtils.name2Uuid(username);

if (stringifiedUuid.isEmpty()) {
this.playerName = "User not found";
this.playerName = "Player not found";
this.errorMessage = "Player UUID not found";
this.profileNotFound = true;
}

Expand Down Expand Up @@ -181,7 +185,8 @@ public boolean isInvisibleTo(PlayerEntity player) {
};
entity.setCustomNameVisible(false);
}).exceptionally(ex -> {
this.playerName = "User not found";
this.playerName = "Player not found";
this.errorMessage = "Player skin not found";
this.profileNotFound = true;
return null;
}).join();
Expand Down

0 comments on commit 12244a2

Please sign in to comment.