]> git.basschouten.com Git - openhab-addons.git/commitdiff
Handle WebSocketException to prevent scheduled job failure (#12944)
authorMark Hilbush <mark@hilbush.com>
Fri, 17 Jun 2022 10:54:26 +0000 (06:54 -0400)
committerGitHub <noreply@github.com>
Fri, 17 Jun 2022 10:54:26 +0000 (12:54 +0200)
Signed-off-by: Mark Hilbush <mark@hilbush.com>
bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveBridgeHandler.java

index 95e7e44c7ce2a9c1ebdf5c8023b6e90172c278d1..42cd4c8b80e3a787210b2ac8499ee50d9e9705ea 100644 (file)
@@ -37,6 +37,7 @@ import org.eclipse.jetty.client.api.Request;
 import org.eclipse.jetty.client.util.StringContentProvider;
 import org.eclipse.jetty.http.HttpMethod;
 import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.WebSocketException;
 import org.eclipse.jetty.websocket.client.WebSocketClient;
 import org.openhab.binding.orbitbhyve.internal.OrbitBhyveConfiguration;
 import org.openhab.binding.orbitbhyve.internal.discovery.OrbitBhyveDiscoveryService;
@@ -183,7 +184,10 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler {
                     updateAllStatuses();
                 } catch (IOException e) {
                     updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
-                            "Error sending ping to a web socket");
+                            "Error sending ping (IOException on web socket)");
+                } catch (WebSocketException e) {
+                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+                            String.format("Error sending ping (WebSocketException: %s)", e.getMessage()));
                 }
             } else {
                 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Web socket creation error");
@@ -426,7 +430,10 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler {
                 localSession.getRemote().sendString(msg);
             } catch (IOException e) {
                 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
-                        "Cannot send hello string to web socket!");
+                        "Error sending hello string (IOException on web socket)");
+            } catch (WebSocketException e) {
+                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+                        String.format("Error sending hello string (WebSocketException: %s)", e.getMessage()));
             }
         }
     }
@@ -466,7 +473,10 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler {
             }
         } catch (IOException e) {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
-                    "Error during program watering execution");
+                    "Error sending program watering execution (IOException on web socket)");
+        } catch (WebSocketException e) {
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+                    String.format("Error sending program watering execution (WebSocketException: %s)", e.getMessage()));
         }
     }
 
@@ -505,7 +515,11 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler {
                         + "\",\"delay\":" + delay + ",\"timestamp\":\"" + dateTime + "\"}");
             }
         } catch (IOException e) {
-            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error during rain delay setting");
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+                    "Error setting rain delay (IOException on web socket)");
+        } catch (WebSocketException e) {
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+                    String.format("Error setting rain delay (WebSocketException: %s)", e.getMessage()));
         }
     }
 
@@ -519,7 +533,11 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler {
                         + "\",\"timestamp\":\"" + dateTime + "\",\"mode\":\"manual\",\"stations\":[]}");
             }
         } catch (IOException e) {
-            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error during watering stopping");
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+                    "Error sending stop watering (IOException on web socket)");
+        } catch (WebSocketException e) {
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+                    String.format("Error sending stop watering (WebSocketException: %s)", e.getMessage()));
         }
     }
 
@@ -555,7 +573,11 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler {
                         + "\",\"device_id\":\"" + deviceId + "\",\"timestamp\":\"" + dateTime + "\"}");
             }
         } catch (IOException e) {
-            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error during setting run mode");
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+                    "Error setting run mode (IOException on web socket)");
+        } catch (WebSocketException e) {
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+                    String.format("Error setting run mode (WebSocketException: %s)", e.getMessage()));
         }
     }