summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main
diff options
context:
space:
mode:
authorJakob Heher <jakob.heher@iaik.tugraz.at>2022-11-16 12:04:34 +0100
committerJakob Heher <jakob.heher@iaik.tugraz.at>2022-11-16 12:04:34 +0100
commit9a705e911485af200937ed4fbbd216f1ecefdea2 (patch)
tree9078c143b86371040edd02ec814a389d4ad7b86c /pdf-over-gui/src/main
parentd649500a3e150f38d1ce00277549604f0762f125 (diff)
downloadpdf-over-9a705e911485af200937ed4fbbd216f1ecefdea2.tar.gz
pdf-over-9a705e911485af200937ed4fbbd216f1ecefdea2.tar.bz2
pdf-over-9a705e911485af200937ed4fbbd216f1ecefdea2.zip
explicit error messages for http non-200
cf. #133
Diffstat (limited to 'pdf-over-gui/src/main')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java17
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java2
-rw-r--r--pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties2
-rw-r--r--pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties2
4 files changed, 20 insertions, 3 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java
index 58762b03..29bf880f 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java
@@ -40,6 +40,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import at.asit.pdfover.commons.Constants;
+import at.asit.pdfover.commons.Messages;
import at.asit.pdfover.gui.bku.mobile.ATrustParser;
import at.asit.pdfover.gui.workflow.states.MobileBKUState;
import at.asit.pdfover.gui.workflow.states.MobileBKUState.UsernameAndPassword;
@@ -60,6 +61,12 @@ public class MobileBKUConnector implements BkuSlConnector {
state.storeRememberedCredentialsTo(this.credentials);
}
+ private class UserDisplayedError extends Exception {
+ private final @Nonnull String msg;
+ @Override public @Nonnull String getMessage() { return this.msg; }
+ private UserDisplayedError(@Nonnull String s) { this.msg = s; }
+ }
+
public @Nonnull UsernameAndPassword credentials = new UsernameAndPassword();
/**
@@ -75,6 +82,9 @@ public class MobileBKUConnector implements BkuSlConnector {
currentRequest = presentResponseToUserAndReturnNextRequest(ISNOTNULL(response.html));
log.debug("Returning security layer response:\n{}", response.slResponse);
return response.slResponse;
+ } catch (UserDisplayedError e) {
+ state.showUnrecoverableError(e.getMessage());
+ throw new IllegalStateException("unreachable", e); /* showUnrecoverableError always throws */
} catch (UserCancelledException e) {
throw e;
} catch (Exception e) {
@@ -93,7 +103,7 @@ public class MobileBKUConnector implements BkuSlConnector {
* @throws URISyntaxException
* @throws InterruptedException
*/
- private @Nonnull ATrustParser.Result sendHTTPRequest(CloseableHttpClient httpClient, ClassicHttpRequest request) throws IOException, ProtocolException, URISyntaxException {
+ private @Nonnull ATrustParser.Result sendHTTPRequest(CloseableHttpClient httpClient, ClassicHttpRequest request) throws IOException, ProtocolException, URISyntaxException, UserDisplayedError {
long now = System.nanoTime();
if ((lastHTTPRequestTime != null) && ((now - lastHTTPRequestTime) < 2e+9)) { /* less than 2s since last request */
++loopHTTPRequestCounter;
@@ -115,7 +125,10 @@ public class MobileBKUConnector implements BkuSlConnector {
}
if (httpStatus != HttpStatus.SC_OK) {
- throw new IOException("Got HTTP status " + httpStatus + " " + Optional.ofNullable(response.getReasonPhrase()).orElse("(null)"));
+ switch (httpStatus) {
+ case HttpStatus.SC_REQUEST_TOO_LONG: throw new UserDisplayedError(Messages.getString("atrusterror.http_413"));
+ default: throw new UserDisplayedError(Messages.formatString("atrusterror.http_generic", httpStatus, Optional.ofNullable(response.getReasonPhrase()).orElse("(null)")));
+ }
}
Header refreshHeader = response.getHeader("refresh");
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 e1ecf39c..cec7acd5 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
@@ -215,7 +215,7 @@ public class MobileBKUState extends State {
}
/**
- * Show an error message to the user with only an "ok" option
+ * Show an error message to the user with only an "ok" option;
* throws UserCancelledException afterwards
*/
public void showUnrecoverableError(final @Nonnull String errorMessage) throws UserCancelledException {
diff --git a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties
index 031b32e6..a1027e3e 100644
--- a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties
+++ b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties
@@ -273,3 +273,5 @@ config.fido2.UnsupportedPlatform=FIDO2 authentication is currently unsupported o
config.fido2.InfoURL=https://www.oesterreich.gv.at/id-austria/haeufige-fragen/allgemeines-zu-id-austria#fido
config.fido2.Group=FIDO2 settings
config.fido2.ByDefault=Select FIDO2 authentication by default
+atrusterror.http_413=a-trust.at rejected request:\nProvided document exceeds size limit.
+atrusterror.http_generic=a-trust.at rejected request:\nHTTP %d %s
diff --git a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties
index 58c10267..82a49c25 100644
--- a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties
+++ b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties
@@ -265,3 +265,5 @@ config.UpdateStatus.CHECKING=Versions-Infos werden abgefragt...
config.UpdateStatus.OUTDATED=Neue Version verfügbar. <a>Herunterladen</a>?
config.UpdateStatus.UP_TO_DATE=Ihre Version ist aktuell. <a>Nochmals prüfen</a>?
config.UpdateStatus.FAILED=Versions-Check fehlgeschlagen. <a>Nochmal versuchen</a>?
+atrusterror.http_413=a-trust.at lehnt Anfrage ab:\nDateigröße des PDF-Dokuments überschreitet Grenzwert.
+atrusterror.http_generic=a-trust.at lehnt Anfrage ab:\nHTTP %d %s