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

[smhi] Catch exception that could cause binding to stop updating channels #10794

Merged
merged 1 commit into from
Jun 5, 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 @@ -15,6 +15,7 @@
import static org.openhab.binding.smhi.internal.SmhiBindingConstants.*;

import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.util.Locale;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
Expand All @@ -26,6 +27,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.JsonParseException;

/**
* Class for handling http requests to Smhi's API and return values.
*
Expand Down Expand Up @@ -88,7 +91,11 @@ public TimeSeries getForecast(double lat, double lon) throws SmhiException, Poin
logger.debug("Received response with status {} - {}", resp.getStatus(), resp.getReason());
switch (resp.getStatus()) {
case 200:
return Parser.parseTimeSeries(resp.getContentAsString());
try {
return Parser.parseTimeSeries(resp.getContentAsString());
} catch (JsonParseException | DateTimeParseException e) {
throw new SmhiException(e);
}
case 400:
case 404:
throw new PointOutOfBoundsException();
Expand Down