[sensebox] Gracefully handle JsonSyntaxException (#10348)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
361a6726fc
commit
0a2a6e738a
|
@ -32,6 +32,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link SenseBoxAPIConnection} is responsible for fetching data from the senseBox API server.
|
* 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
|
// the caching layer does not like null values
|
||||||
SenseBoxData result = new SenseBoxData();
|
SenseBoxData result = new SenseBoxData();
|
||||||
|
|
||||||
|
String body = null;
|
||||||
try {
|
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);
|
logger.trace("Fetched Data: {}", body);
|
||||||
SenseBoxData parsedData = gson.fromJson(body, SenseBoxData.class);
|
SenseBoxData parsedData = gson.fromJson(body, SenseBoxData.class);
|
||||||
|
@ -148,6 +150,10 @@ public class SenseBoxAPIConnection {
|
||||||
logger.trace("=================================");
|
logger.trace("=================================");
|
||||||
|
|
||||||
result = parsedData;
|
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) {
|
} catch (IOException e) {
|
||||||
logger.debug("IO problems while fetching data: {} / {}", query, e.getMessage());
|
logger.debug("IO problems while fetching data: {} / {}", query, e.getMessage());
|
||||||
result.setStatus(ThingStatus.OFFLINE);
|
result.setStatus(ThingStatus.OFFLINE);
|
||||||
|
|
Loading…
Reference in New Issue