Improve handling of empty JSON repsonses from ParksNPeaks (and potentially others)

This commit is contained in:
Ian Renton
2026-09-19 10:49:09 +01:00
parent c9c8ffc1f7
commit 682e2c267c
10 changed files with 27 additions and 17 deletions
+6 -1
View File
@@ -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})")