From 1a75766bbde6ff57b9578dcd99b36c4daaca4f5d Mon Sep 17 00:00:00 2001 From: Anders Alfredsson Date: Wed, 2 Jun 2021 12:30:58 +0200 Subject: [PATCH] Catch exception that could cause binding to stop updating channels Signed-off-by: Anders Alfredsson --- .../org/openhab/binding/smhi/internal/SmhiConnector.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiConnector.java b/bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiConnector.java index aa42d7f29b083..8e79aa1623104 100644 --- a/bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiConnector.java +++ b/bundles/org.openhab.binding.smhi/src/main/java/org/openhab/binding/smhi/internal/SmhiConnector.java @@ -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; @@ -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. * @@ -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();