]> git.basschouten.com Git - openhab-addons.git/commitdiff
[sensebox] Gracefully handle JsonSyntaxException (#10348)
authorChristoph Weitkamp <github@christophweitkamp.de>
Fri, 26 Mar 2021 16:47:05 +0000 (17:47 +0100)
committerGitHub <noreply@github.com>
Fri, 26 Mar 2021 16:47:05 +0000 (17:47 +0100)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
bundles/org.openhab.binding.sensebox/src/main/java/org/openhab/binding/sensebox/internal/SenseBoxAPIConnection.java

index 907fa8782e8a659a3e7b39e9757c727efefb39bc..0e14c975b9c8cf448cad130b34ed9b7e315bb02a 100644 (file)
@@ -32,6 +32,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.gson.Gson;
+import com.google.gson.JsonSyntaxException;
 
 /**
  * The {@link SenseBoxAPIConnection} is responsible for fetching data from the senseBox API server.
@@ -63,8 +64,9 @@ public class SenseBoxAPIConnection {
         // the caching layer does not like null values
         SenseBoxData result = new SenseBoxData();
 
+        String body = null;
         try {
-            String body = HttpUtil.executeUrl(METHOD, query, HEADERS, null, null, TIMEOUT);
+            body = HttpUtil.executeUrl(METHOD, query, HEADERS, null, null, TIMEOUT);
 
             logger.trace("Fetched Data: {}", body);
             SenseBoxData parsedData = gson.fromJson(body, SenseBoxData.class);
@@ -148,6 +150,10 @@ public class SenseBoxAPIConnection {
             logger.trace("=================================");
 
             result = parsedData;
+        } catch (JsonSyntaxException e) {
+            logger.debug("An error occurred while parsing the data into desired class: {} / {} / {}", body,
+                    SenseBoxData.class.getName(), e.getMessage());
+            result.setStatus(ThingStatus.OFFLINE);
         } catch (IOException e) {
             logger.debug("IO problems while fetching data: {} / {}", query, e.getMessage());
             result.setStatus(ThingStatus.OFFLINE);