Skip to content

Commit

Permalink
[smhi] Catch exception that could cause binding to stop updating chan…
Browse files Browse the repository at this point in the history
…nels (openhab#10794)

Signed-off-by: Anders Alfredsson <[email protected]>
  • Loading branch information
pacive authored Jun 5, 2021
1 parent 51c04ad commit 1e55a2f
Showing 1 changed file with 8 additions and 1 deletion.
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

0 comments on commit 1e55a2f

Please sign in to comment.