Skip to content

Commit

Permalink
Add a descriptive error for people with a bad DNS
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Nov 18, 2024
1 parent ab0f268 commit e17c778
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/com/minelittlepony/hdskins/server/Gateway.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.minelittlepony.hdskins.server;

import java.io.IOException;
import java.nio.channels.UnresolvedAddressException;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.Consumer;
Expand All @@ -22,6 +23,7 @@

public class Gateway {
public static final Text ERR_SESSION = Text.translatable("hdskins.error.session");
public static final Text ERR_DNS = Text.translatable("hdskins.error.dns");

private static final Logger LOGGER = LogManager.getLogger();

Expand Down Expand Up @@ -146,6 +148,9 @@ public void handleException(Throwable throwable, Consumer<Text> errorCallback) {

if (throwable instanceof AuthenticationUnavailableException) {
setOffline(true);
} else if (throwable instanceof UnresolvedAddressException) {
errorCallback.accept(ERR_DNS);
setOffline(true);
} else if (throwable instanceof InvalidCredentialsException) {
errorCallback.accept(ERR_SESSION);
} else if (throwable instanceof AuthenticationException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.lang.reflect.Type;
import java.net.http.*;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.channels.UnresolvedAddressException;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -35,7 +36,7 @@ static MoreHttpResponses execute(HttpRequest request) throws IOException {
try {
HttpResponse<InputStream> response = CLIENT.send(request, BodyHandlers.ofInputStream());
return () -> response;
} catch (InterruptedException e) {
} catch (InterruptedException | UnresolvedAddressException e) {
throw new IOException(e);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/hdskins/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"hdskins.error.offline": "- Server Offline -",
"hdskins.error.session": "Invalid session: Please try restarting Minecraft",
"hdskins.error.session.short": "Invalid session",
"hdskins.error.dns": "Server is unreachable. Please check your DNS settings and restart the game.",
"hdskins.status.busy": "Working...",
"hdskins.open.title": "Choose skin",
"hdskins.directory.up": "Parent Directory",
Expand Down

0 comments on commit e17c778

Please sign in to comment.