Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sensebox] Gracefully handle JsonSyntaxException #10348

Merged
merged 1 commit into from
Mar 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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