Re-authorize if token has expired.

This commit is contained in:
Matthew Messinger 2018-07-28 01:47:16 -04:00
parent c60cd9dae6
commit 74fef1a240

View file

@ -74,6 +74,23 @@ public class ValhallaSkinServer implements SkinServer {
try (CloseableHttpClient client = HttpClients.createSystem()) { try (CloseableHttpClient client = HttpClients.createSystem()) {
authorize(client, session); authorize(client, session);
try {
return upload(client, session, image, type, metadata);
} catch (IOException e) {
if (e.getMessage().equals("Authorization failed")) {
accessToken = null;
authorize(client, session);
return upload(client, session, image, type, metadata);
}
throw e;
}
}
}, HDSkinManager.skinUploadExecutor);
}
private SkinUploadResponse upload(CloseableHttpClient client, Session session, @Nullable URI image,
MinecraftProfileTexture.Type type, Map<String, String> metadata)
throws IOException {
GameProfile profile = session.getProfile(); GameProfile profile = session.getProfile();
if (image == null) { if (image == null) {
@ -88,8 +105,7 @@ public class ValhallaSkinServer implements SkinServer {
default: default:
throw new IOException("Unsupported URI scheme: " + image.getScheme()); throw new IOException("Unsupported URI scheme: " + image.getScheme());
} }
}
}, HDSkinManager.skinUploadExecutor);
} }
private SkinUploadResponse resetSkin(CloseableHttpClient client, GameProfile profile, MinecraftProfileTexture.Type type) throws IOException { private SkinUploadResponse resetSkin(CloseableHttpClient client, GameProfile profile, MinecraftProfileTexture.Type type) throws IOException {