Skip to content

Commit

Permalink
[sensebox] Gracefully handle JsonSyntaxException (openhab#10348)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
  • Loading branch information
cweitkamp authored and thinkingstone committed Nov 7, 2021
1 parent 208a024 commit a5f6b66
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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.
Expand Down Expand Up @@ -63,8 +64,9 @@ public SenseBoxData reallyFetchDataFromServer(String senseBoxId) {
// 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);
Expand Down Expand Up @@ -148,6 +150,10 @@ public SenseBoxData reallyFetchDataFromServer(String senseBoxId) {
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);
Expand Down

0 comments on commit a5f6b66

Please sign in to comment.