Skip to content

Commit

Permalink
Improve IRCELINE request handling robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed May 20, 2019
1 parent f3ec903 commit 8cebfe0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Luftdatenpumpe changelog

in progress
===========
- Improve IRCELINE request handling robustness


2019-05-19 0.12.1
Expand Down
14 changes: 13 additions & 1 deletion luftdatenpumpe/source/irceline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from datetime import datetime, timedelta
from operator import itemgetter

from requests import HTTPError
from rfc3339 import rfc3339
from munch import munchify, Munch
from urllib.parse import urljoin
Expand Down Expand Up @@ -53,7 +54,18 @@ def send_request(self, endpoint=None, params=None):
url = urljoin(self.uri, endpoint)
log.debug(f'Requesting IRCELINE live API at {url}')
params = params or {}
return self.session.get(url, params=params, timeout=self.timeout).json()

response = self.session.get(url, params=params, timeout=self.timeout)
if response.status_code != 200:
try:
reason = response.json()
except:
reason = 'unknown'
message = f'Request failed: {reason}'
log.error(message)
response.raise_for_status()

return response.json()

def get_stations(self):
"""
Expand Down

0 comments on commit 8cebfe0

Please sign in to comment.