1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2025-02-26 03:21:51 +01:00

Clean up error reporting for Minecraft API authentication

This commit is contained in:
Henry Le Grys 2021-02-16 22:16:42 +00:00
parent ff12d154c8
commit 8eb66d4c67
2 changed files with 14 additions and 13 deletions

View File

@ -28,21 +28,21 @@ public class MinecraftServicesAuthorizer {
public static McProfileResponse getUserProfile(McAuthResponse auth) public static McProfileResponse getUserProfile(McAuthResponse auth)
throws IOException, InterruptedException, AuthenticationException { throws IOException, InterruptedException, AuthenticationException {
HttpRequest request = HttpRequest.get(MC_SERVICES_PROFILE) return HttpRequest.get(MC_SERVICES_PROFILE)
.header("Authorization", auth.getAuthorization()) .header("Authorization", auth.getAuthorization())
.execute(); .execute()
.expectResponseCodeOr(200, req -> {
if (request.getResponseCode() == 200) { McServicesError error = req.returnContent().asJson(McServicesError.class);
return request.returnContent().asJson(McProfileResponse.class);
} else {
McServicesError error = request.returnContent().asJson(McServicesError.class);
if (error.getError().equals("NOT_FOUND")) { if (error.getError().equals("NOT_FOUND")) {
throw new AuthenticationException("No Minecraft profile", return new AuthenticationException("No Minecraft profile",
SharedLocale.tr("login.minecraftNotOwnedError")); SharedLocale.tr("login.minecraftNotOwnedError"));
} }
throw new AuthenticationException(error.getErrorMessage()); return new AuthenticationException(error.getErrorMessage(),
} SharedLocale.tr("login.minecraft.error", error.getErrorMessage()));
})
.returnContent()
.asJson(McProfileResponse.class);
} }
} }

View File

@ -116,6 +116,7 @@ login.xbox.noXboxAccount=That account does not have an Xbox account associated!
login.xbox.isChild=The account is a child (under 18) and cannot proceed unless it is part of a Family. login.xbox.isChild=The account is a child (under 18) and cannot proceed unless it is part of a Family.
login.xbox.unknown=An unknown error occurred while logging in with Xbox (XErr {0}) login.xbox.unknown=An unknown error occurred while logging in with Xbox (XErr {0})
login.xbox.errorMessage=An unknown error occurred while logging in with Xbox: {0} login.xbox.errorMessage=An unknown error occurred while logging in with Xbox: {0}
login.minecraft.error=An error occurred while authorizing with Minecraft services: {0}
console.title=Messages and Errors console.title=Messages and Errors
console.launcherConsoleTitle=Launcher Messages console.launcherConsoleTitle=Launcher Messages