From adf9c7f968c387b8b5641e4fcf253a2b3512db4d Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Thu, 3 Nov 2022 14:45:33 +0100 Subject: more generic error page detection (grml why no uniquely identifiable id...) cf. #130 --- .../asit/pdfover/gui/bku/mobile/ATrustParser.java | 23 ++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustParser.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustParser.java index 03ddd0c3..7978187d 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustParser.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustParser.java @@ -93,15 +93,26 @@ public class ATrustParser { private ErrorBlock(@Nonnull org.jsoup.nodes.Document htmlDocument, @Nonnull Map formOptions) throws ComponentParseFailed { super(htmlDocument, formOptions); - if (!htmlDocument.baseUri().contains("/error.aspx")) + + try { + String documentPath = new URI(htmlDocument.baseUri()).getPath(); + String aspxFile = documentPath.substring(documentPath.lastIndexOf('/')); + + // gods this is such a hack, why can't they have a proper error element or something + if (!(aspxFile.startsWith("/error") && aspxFile.endsWith(".aspx"))) + throw new ComponentParseFailed(); + } catch (URISyntaxException ex) { + log.warn("Failed to parse document base URI as URI? ({})", htmlDocument.baseUri()); throw new ComponentParseFailed(); - + } + this.isRecoverable = (htmlDocument.selectFirst("#Button_Back") != null); - String errorText = getElementEnsureNotNull("#Label1").ownText(); - if (errorText.startsWith("Fehler:")) - errorText = errorText.substring(7); - this.errorText = ISNOTNULL(errorText.trim()); + StringBuilder errorText = new StringBuilder(getElementEnsureNotNull("#Label1").ownText().trim()); + var detailLabel = this.htmlDocument.selectFirst("#LabelDetail"); + if (detailLabel != null) + errorText.append("\n").append(detailLabel.ownText().trim()); + this.errorText = ISNOTNULL(errorText.toString()); } } -- cgit v1.2.3