Skip to content

Commit

Permalink
Show an error if the remote isn't reachable
Browse files Browse the repository at this point in the history
When connecting as a client, only the log would display that the server wasn't reachable. Now there's a requester.
  • Loading branch information
zapek committed Dec 21, 2024
1 parent cace63f commit 6f04d22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ui/src/main/java/io/xeres/ui/PrimaryStageInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
import io.xeres.ui.client.message.ChatFrameHandler;
import io.xeres.ui.client.message.MessageClient;
import io.xeres.ui.controller.chat.ChatViewController;
import io.xeres.ui.support.util.UiUtils;
import io.xeres.ui.support.window.WindowManager;
import javafx.application.Platform;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClientRequestException;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Hooks;

Expand Down Expand Up @@ -74,6 +76,7 @@ public void onApplicationEvent(StageReadyEvent event)
windowManager.openAccountCreation(event.getStage());
}
})
.doOnError(WebClientRequestException.class, e -> UiUtils.showAlertError(e, Platform::exit))
.subscribe();
}

Expand Down
9 changes: 9 additions & 0 deletions ui/src/main/java/io/xeres/ui/support/util/UiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ private UiUtils()
* @param t the throwable
*/
public static void showAlertError(Throwable t)
{
showAlertError(t, null);
}

public static void showAlertError(Throwable t, Runnable action)
{
Platform.runLater(() -> {
if (t instanceof WebClientResponseException e)
Expand Down Expand Up @@ -109,6 +114,10 @@ public static void showAlertError(Throwable t)
{
alert(ERROR, "Error", t.getMessage(), ExceptionUtils.getStackTrace(t));
}
if (action != null)
{
action.run();
}
log.error("Error: {}", t.getMessage(), t);
});
}
Expand Down

0 comments on commit 6f04d22

Please sign in to comment.