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:
@@ -41,15 +41,20 @@ class HTTPSpotProvider(SpotProvider):
|
||||
# Request data from API
|
||||
logging.debug("Polling " + self.name + " spot API...")
|
||||
http_response = requests.get(self._url, headers=HTTP_HEADERS, timeout=(5, 30))
|
||||
# Pass off to the subclass for processing
|
||||
new_spots = self._http_response_to_spots(http_response)
|
||||
# Submit the new spots for processing. There might not be any spots for the less popular programs.
|
||||
if new_spots:
|
||||
self._submit_batch(new_spots)
|
||||
# Check response code was good
|
||||
if http_response.status_code == 200:
|
||||
# Pass off to the subclass for processing
|
||||
new_spots = self._http_response_to_spots(http_response)
|
||||
# Submit the new spots for processing. There might not be any spots for the less popular programs.
|
||||
if new_spots:
|
||||
self._submit_batch(new_spots)
|
||||
|
||||
self.status = "OK"
|
||||
self.last_update_time = datetime.now(pytz.UTC)
|
||||
logging.debug("Received data from " + self.name + " spot API.")
|
||||
self.status = "OK"
|
||||
self.last_update_time = datetime.now(pytz.UTC)
|
||||
logging.debug("Received data from " + self.name + " spot API.")
|
||||
else:
|
||||
self.status = "Error"
|
||||
logging.warning(f"{self.name} spot API returned HTTP {http_response.status_code}.")
|
||||
|
||||
except Exception:
|
||||
self.status = "Error"
|
||||
|
||||
Reference in New Issue
Block a user