Handle WebSocketException to prevent scheduled job failure (#12944)

Signed-off-by: Mark Hilbush <mark@hilbush.com>
This commit is contained in:
Mark Hilbush 2022-06-17 06:54:26 -04:00 committed by GitHub
parent 72f947dee0
commit 740f843157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,6 +37,7 @@ import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.util.StringContentProvider; import org.eclipse.jetty.client.util.StringContentProvider;
import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.openhab.binding.orbitbhyve.internal.OrbitBhyveConfiguration; import org.openhab.binding.orbitbhyve.internal.OrbitBhyveConfiguration;
import org.openhab.binding.orbitbhyve.internal.discovery.OrbitBhyveDiscoveryService; import org.openhab.binding.orbitbhyve.internal.discovery.OrbitBhyveDiscoveryService;
@ -183,7 +184,10 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler {
updateAllStatuses(); updateAllStatuses();
} catch (IOException e) { } catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, 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 { } else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Web socket creation error"); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Web socket creation error");
@ -426,7 +430,10 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler {
localSession.getRemote().sendString(msg); localSession.getRemote().sendString(msg);
} catch (IOException e) { } catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, 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) { } catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, 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 + "\"}"); + "\",\"delay\":" + delay + ",\"timestamp\":\"" + dateTime + "\"}");
} }
} catch (IOException e) { } 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\":[]}"); + "\",\"timestamp\":\"" + dateTime + "\",\"mode\":\"manual\",\"stations\":[]}");
} }
} catch (IOException e) { } 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 + "\"}"); + "\",\"device_id\":\"" + deviceId + "\",\"timestamp\":\"" + dateTime + "\"}");
} }
} catch (IOException e) { } 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()));
} }
} }