From 6b442c771e2cc247c8fdb516113d2b4ae9512c38 Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Tue, 9 Feb 2021 03:06:37 +0000 Subject: [PATCH] Improve authentication error messages --- .../skcraft/launcher/auth/AuthenticationException.java | 4 ++++ .../com/skcraft/launcher/auth/MicrosoftLoginService.java | 2 +- .../com/skcraft/launcher/auth/YggdrasilLoginService.java | 6 ++---- .../auth/microsoft/MinecraftServicesAuthorizer.java | 8 +++++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/launcher/src/main/java/com/skcraft/launcher/auth/AuthenticationException.java b/launcher/src/main/java/com/skcraft/launcher/auth/AuthenticationException.java index 4dc3f4f..675d32e 100644 --- a/launcher/src/main/java/com/skcraft/launcher/auth/AuthenticationException.java +++ b/launcher/src/main/java/com/skcraft/launcher/auth/AuthenticationException.java @@ -17,6 +17,10 @@ public class AuthenticationException extends LauncherException { super(message, localizedMessage); } + public AuthenticationException(String message) { + super(message, message); + } + public AuthenticationException(Throwable cause, String localizedMessage) { super(cause, localizedMessage); } diff --git a/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java b/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java index 476fd5d..6c2f44e 100644 --- a/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java +++ b/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java @@ -73,7 +73,7 @@ public class MicrosoftLoginService implements LoginService { } else { TokenError error = request.returnContent().asJson(TokenError.class); - throw new AuthenticationException(error.errorDescription, error.errorDescription); + throw new AuthenticationException(error.errorDescription); } } diff --git a/launcher/src/main/java/com/skcraft/launcher/auth/YggdrasilLoginService.java b/launcher/src/main/java/com/skcraft/launcher/auth/YggdrasilLoginService.java index be78e63..8951ebe 100644 --- a/launcher/src/main/java/com/skcraft/launcher/auth/YggdrasilLoginService.java +++ b/launcher/src/main/java/com/skcraft/launcher/auth/YggdrasilLoginService.java @@ -11,7 +11,6 @@ import com.skcraft.launcher.util.HttpRequest; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.ToString; -import lombok.extern.java.Log; import java.io.IOException; import java.net.URL; @@ -21,7 +20,6 @@ import java.util.Map; /** * Creates authenticated sessions using the Mojang Yggdrasil login protocol. */ -@Log @RequiredArgsConstructor public class YggdrasilLoginService implements LoginService { @@ -52,8 +50,8 @@ public class YggdrasilLoginService implements LoginService { if (req.getResponseCode() != 200) { ErrorResponse error = req.returnContent().asJson(ErrorResponse.class); - log.warning(error.toString()); - throw new AuthenticationException(error.getErrorMessage(), error.getErrorMessage()); + + throw new AuthenticationException(error.getErrorMessage()); } else { AuthenticateResponse response = req.returnContent().asJson(AuthenticateResponse.class); Profile profile = response.getSelectedProfile(); diff --git a/launcher/src/main/java/com/skcraft/launcher/auth/microsoft/MinecraftServicesAuthorizer.java b/launcher/src/main/java/com/skcraft/launcher/auth/microsoft/MinecraftServicesAuthorizer.java index 4fb648d..94062f7 100644 --- a/launcher/src/main/java/com/skcraft/launcher/auth/microsoft/MinecraftServicesAuthorizer.java +++ b/launcher/src/main/java/com/skcraft/launcher/auth/microsoft/MinecraftServicesAuthorizer.java @@ -3,6 +3,7 @@ package com.skcraft.launcher.auth.microsoft; import com.skcraft.launcher.auth.AuthenticationException; import com.skcraft.launcher.auth.microsoft.model.*; import com.skcraft.launcher.util.HttpRequest; +import com.skcraft.launcher.util.SharedLocale; import java.io.IOException; import java.net.URL; @@ -36,7 +37,12 @@ public class MinecraftServicesAuthorizer { } else { McServicesError error = request.returnContent().asJson(McServicesError.class); - throw new AuthenticationException(error.getErrorMessage(), error.getErrorMessage()); + if (error.getError().equals("NOT_FOUND")) { + throw new AuthenticationException("No Minecraft profile", + SharedLocale.tr("login.minecraftNotOwnedError")); + } + + throw new AuthenticationException(error.getErrorMessage()); } } }