Skip to content

Commit

Permalink
Adding exception catching
Browse files Browse the repository at this point in the history
  • Loading branch information
Leobaillard committed Oct 22, 2015
1 parent fc245ba commit e97432b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions vstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ def get_station_data(station_id):

def get_api_call(api_func):
api_url = config['jcd_apiurl'] + api_func + "?apiKey=" + config['jcd_apikey'] + "&contract=" + config['jcd_contract']
data = requests.get(api_url)
if data.status_code == 200:
return data.json()
else:
try:
data = requests.get(api_url)
if data.status_code == 200:
return data.json()
else:
print("Error fetching data, creating graphite event")
create_graphite_event("Error fetching API data (" + api_func +")", ["error"])
return json.loads("{}")
except:
print("Error fetching data, creating graphite event")
create_graphite_event("Error fetching API data (" + api_func +")", ["error"])
return json.loads("{}")
Expand Down

0 comments on commit e97432b

Please sign in to comment.