From bf04fba3b1ff92b4288c37c474c8e4b9d4e2e342 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Thu, 14 Jul 2022 13:27:06 +0200 Subject: better error message if internet connection is unavailable cf. #47 --- .../gui/workflow/states/MobileBKUState.java | 31 ++++++++++------------ 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 09f67602..594e46c8 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java @@ -16,6 +16,7 @@ package at.asit.pdfover.gui.workflow.states; import java.io.InputStream; +import java.net.UnknownHostException; import java.util.Timer; import java.util.TimerTask; @@ -164,11 +165,18 @@ public class MobileBKUState extends State { * the exception */ public void displayError(Exception e) { - String message = Messages.getString("error.Unexpected"); - log.error(message, e); - String errormsg = e.getLocalizedMessage(); - if (errormsg != null && !errormsg.isEmpty()) - message += ": " + errormsg; + String message = null; + if (e instanceof UnknownHostException) + { + log.error("Failed to resolve hostname", e); + message = String.format(Messages.getString("error.CouldNotResolveHostname"), e.getMessage()); + } else { + message = Messages.getString("error.Unexpected"); + log.error(message, e); + String errormsg = e.getLocalizedMessage(); + if (errormsg != null && !errormsg.isEmpty()) + message += ": " + errormsg; + } displayError(message); } @@ -548,18 +556,7 @@ public class MobileBKUState extends State { this.signingState.setUseBase64Request(this.handler.useBase64Request()); if (this.threadException != null) { - String message = Messages.getString("error.Unexpected"); - log.error(message, this.threadException); - String errormsg = this.threadException.getLocalizedMessage(); - if (errormsg != null && !errormsg.isEmpty()) - message += ": " + errormsg; - ErrorDialog error = new ErrorDialog( - getStateMachine().getMainShell(), - message, BUTTONS.OK); - // error.setException(this.threadException); - // this.setNextState(error); - error.open(); - getStateMachine().exit(); + displayError(this.threadException); return; } -- cgit v1.2.3