]> git.basschouten.com Git - openhab-addons.git/commitdiff
improve error handling (#9543)
authorJ-N-K <J-N-K@users.noreply.github.com>
Sun, 27 Dec 2020 17:21:21 +0000 (18:21 +0100)
committerGitHub <noreply@github.com>
Sun, 27 Dec 2020 17:21:21 +0000 (18:21 +0100)
Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064CommunicationException.java
bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPConnector.java

index 8e1bee6c646dbfc04da47a75463ff19cd37d10be..8ea71ab28d48f071be9c91733c1af8c45a87101c 100644 (file)
@@ -22,6 +22,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 @NonNullByDefault
 public class Tr064CommunicationException extends Exception {
     private static final long serialVersionUID = 1L;
+    private String soapError = "";
+    private int httpError = 0;
 
     public Tr064CommunicationException(Exception e) {
         super(e);
@@ -30,4 +32,18 @@ public class Tr064CommunicationException extends Exception {
     public Tr064CommunicationException(String s) {
         super(s);
     }
+
+    public Tr064CommunicationException(String s, Integer httpError, String soapError) {
+        super(s);
+        this.httpError = httpError;
+        this.soapError = soapError;
+    };
+
+    public String getSoapError() {
+        return soapError;
+    }
+
+    public int getHttpError() {
+        return httpError;
+    }
 }
index 35da04b8e3bc53e98d5b414413db418aaa5acf5e..d1bb97c14a1a9e25808fe12940688afe8c493151 100644 (file)
@@ -153,7 +153,7 @@ public class SOAPConnector {
                     String soapReason = getSOAPElement(soapMessage, "errorDescription").orElse("unknown");
                     String error = String.format("HTTP-Response-Code %d (%s), SOAP-Fault: %s (%s)",
                             response.getStatus(), response.getReason(), soapError, soapReason);
-                    throw new Tr064CommunicationException(error);
+                    throw new Tr064CommunicationException(error, response.getStatus(), soapError);
                 }
                 return soapMessage;
             }
@@ -248,7 +248,17 @@ public class SOAPConnector {
                     .orElseThrow(() -> new Tr064CommunicationException("failed to transform '"
                             + channelConfig.getChannelTypeDescription().getGetAction().getArgument() + "'"));
         } catch (Tr064CommunicationException e) {
-            logger.info("Failed to get {}: {}", channelConfig, e.getMessage());
+            if (e.getHttpError() == 500) {
+                switch (e.getSoapError()) {
+                    case "714":
+                        // NoSuchEntryInArray usually is an unknown entry in the MAC list
+                        logger.debug("Failed to get {}: {}", channelConfig, e.getMessage());
+                        return UnDefType.UNDEF;
+                    default:
+                }
+            }
+            // all other cases are an error
+            logger.warn("Failed to get {}: {}", channelConfig, e.getMessage());
             return UnDefType.UNDEF;
         }
     }