From 3f4aac948519ccf6fa941d17be809af1e2d4ae36 Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Sat, 13 Jan 2024 13:27:29 +0100 Subject: [PATCH] Fix exception handling for InfluxDB 1.x (#16234) Fixes #16233 Signed-off-by: Jacob Laursen --- .../influx1/InfluxDB1RepositoryImpl.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/influx1/InfluxDB1RepositoryImpl.java b/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/influx1/InfluxDB1RepositoryImpl.java index b0beb966032..f33a6b8e66c 100644 --- a/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/influx1/InfluxDB1RepositoryImpl.java +++ b/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/influx1/InfluxDB1RepositoryImpl.java @@ -75,12 +75,17 @@ public class InfluxDB1RepositoryImpl implements InfluxDBRepository { @Override public boolean connect() { - final InfluxDB createdClient = InfluxDBFactory.connect(configuration.getUrl(), configuration.getUser(), - configuration.getPassword()); - createdClient.setDatabase(configuration.getDatabaseName()); - createdClient.setRetentionPolicy(configuration.getRetentionPolicy()); - createdClient.enableBatch(200, 100, TimeUnit.MILLISECONDS); - this.client = createdClient; + try { + final InfluxDB createdClient = InfluxDBFactory.connect(configuration.getUrl(), configuration.getUser(), + configuration.getPassword()); + createdClient.setDatabase(configuration.getDatabaseName()); + createdClient.setRetentionPolicy(configuration.getRetentionPolicy()); + createdClient.enableBatch(200, 100, TimeUnit.MILLISECONDS); + this.client = createdClient; + } catch (InfluxException | InfluxDBException e) { + logger.debug("Connection failed", e); + return false; + } return checkConnectionStatus(); }