mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 02:21:42 +00:00
Improve error handling to spare the server log from user's malformed requests and stop trying to parse data from providers if the HTTP status was not 200
This commit is contained in:
@@ -39,12 +39,17 @@ class HTTPSolarConditionsProvider(SolarConditionsProvider):
|
||||
try:
|
||||
logging.debug("Polling " + self.name + " solar conditions API...")
|
||||
http_response = requests.get(self._url, headers=HTTP_HEADERS, timeout=(5, 30))
|
||||
new_data = self._http_response_to_solar_conditions(http_response)
|
||||
self.update_data(new_data)
|
||||
# Check response code was good
|
||||
if http_response.status_code == 200:
|
||||
new_data = self._http_response_to_solar_conditions(http_response)
|
||||
self.update_data(new_data)
|
||||
|
||||
self.status = "OK"
|
||||
self.last_update_time = datetime.now(pytz.UTC)
|
||||
logging.debug("Received data from " + self.name + " solar conditions API.")
|
||||
self.status = "OK"
|
||||
self.last_update_time = datetime.now(pytz.UTC)
|
||||
logging.debug("Received data from " + self.name + " solar conditions API.")
|
||||
else:
|
||||
self.status = "Error"
|
||||
logging.warning(f"{self.name} solar conditions API returned HTTP {http_response.status_code}.")
|
||||
|
||||
except Exception:
|
||||
self.status = "Error"
|
||||
|
||||
Reference in New Issue
Block a user