From 682e2c267c05fc8aa2f3369e0293008064e68f04 Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Sat, 19 Sep 2026 10:49:09 +0100 Subject: [PATCH] Improve handling of empty JSON repsonses from ParksNPeaks (and potentially others) --- providers/alert/http_alert_provider.py | 7 ++++++- providers/spot/http_spot_provider.py | 7 ++++++- templates/add_spot.html | 2 +- templates/alerts.html | 2 +- templates/bands.html | 4 ++-- templates/base.html | 10 +++++----- templates/conditions.html | 2 +- templates/map.html | 4 ++-- templates/spots.html | 4 ++-- templates/status.html | 2 +- 10 files changed, 27 insertions(+), 17 deletions(-) diff --git a/providers/alert/http_alert_provider.py b/providers/alert/http_alert_provider.py index 83d1c6b..a06dd45 100644 --- a/providers/alert/http_alert_provider.py +++ b/providers/alert/http_alert_provider.py @@ -4,7 +4,7 @@ from threading import Event, Thread import pytz import requests -from requests.exceptions import ConnectionError, ConnectTimeout, ReadTimeout +from requests.exceptions import ConnectionError, ConnectTimeout, JSONDecodeError, ReadTimeout from core.constants import HTTP_HEADERS from providers.alert.alert_provider import AlertProvider @@ -64,9 +64,14 @@ class HTTPAlertProvider(AlertProvider): logger.warning(f"HTTP {http_response.status_code} when calling {self.name} alerts API.") except ConnectionError: + self.status = "Error" logger.warning(f"Connection error when accessing {self.name} alerts API.") except (ConnectTimeout, ReadTimeout): + self.status = "Error" logger.warning(f"Timeout when accessing {self.name} alerts API.") + except JSONDecodeError: + self.status = "Error" + logger.warning(f"Invalid or empty JSON response from {self.name} alert API.") except Exception: self.status = "Error" logger.exception(f"Exception in HTTP JSON Alert Provider ({self.name})") diff --git a/providers/spot/http_spot_provider.py b/providers/spot/http_spot_provider.py index 124742a..f71f81f 100644 --- a/providers/spot/http_spot_provider.py +++ b/providers/spot/http_spot_provider.py @@ -4,7 +4,7 @@ from threading import Event, Thread import pytz import requests -from requests.exceptions import ConnectionError, ConnectTimeout, ReadTimeout +from requests.exceptions import ConnectionError, ConnectTimeout, JSONDecodeError, ReadTimeout from core.constants import HTTP_HEADERS from providers.spot.spot_provider import SpotProvider @@ -73,9 +73,14 @@ class HTTPSpotProvider(SpotProvider): logger.warning(f"HTTP {http_response.status_code} when calling {self.name} spot API.") except ConnectionError: + self.status = "Error" logger.warning(f"Connection error when accessing {self.name} spots API.") except (ConnectTimeout, ReadTimeout): + self.status = "Error" logger.warning(f"Timeout when accessing {self.name} spots API.") + except JSONDecodeError: + self.status = "Error" + logger.warning(f"Invalid or empty JSON response from {self.name} spots API.") except Exception: self.status = "Error" logger.exception(f"Exception in HTTP Spot Provider ({self.name})") diff --git a/templates/add_spot.html b/templates/add_spot.html index 3d9632a..30ad8af 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -77,7 +77,7 @@ - + diff --git a/templates/alerts.html b/templates/alerts.html index db16f4b..4b1bc81 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -83,7 +83,7 @@ - + diff --git a/templates/bands.html b/templates/bands.html index 4c6b19d..133b326 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -76,8 +76,8 @@ - - + + diff --git a/templates/base.html b/templates/base.html index 27c8fae..95a43e6 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% extends "skeleton.html" %} {% block head_extra %} - + @@ -16,10 +16,10 @@ window.fetchEventSource = fetchEventSource; - - - - + + + + {% end %} {% block body %}
diff --git a/templates/conditions.html b/templates/conditions.html index 6722749..7cfe8ea 100644 --- a/templates/conditions.html +++ b/templates/conditions.html @@ -284,7 +284,7 @@
- + diff --git a/templates/map.html b/templates/map.html index d956aa2..49dbd39 100644 --- a/templates/map.html +++ b/templates/map.html @@ -113,8 +113,8 @@ const CARTODB_API_KEY = "{{ web_ui_options.get('cartodb_api_key', '') }}"; - - + + diff --git a/templates/spots.html b/templates/spots.html index 01cf1f3..634f0d0 100644 --- a/templates/spots.html +++ b/templates/spots.html @@ -125,8 +125,8 @@ - - + + diff --git a/templates/status.html b/templates/status.html index cff0984..1afa8d5 100644 --- a/templates/status.html +++ b/templates/status.html @@ -96,7 +96,7 @@ - +