Skip to content

Commit

Permalink
adding additional error handling to prevent api leaks to channel
Browse files Browse the repository at this point in the history
  • Loading branch information
RustyBower committed Apr 11, 2021
1 parent 6022f4e commit d7474bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions sopel_modules/weather/providers/weather/darksky.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def darksky_forecast(bot, latitude, longitude, location):
'exclude': 'currently,minutely,hourly,alerts,flags', # Exclude extra data we don't want/need
'units': 'si'
}
r = requests.get(url, params=params)
try:
r = requests.get(url, params=params)
except:
raise Exception("An Error Occurred. Check Logs For More Information.")
data = r.json()
if r.status_code != 200:
raise Exception('Error: {}'.format(data['error']))
Expand All @@ -42,7 +45,10 @@ def darksky_weather(bot, latitude, longitude, location):
'exclude': 'minutely,hourly,daily,alerts,flags', # Exclude extra data we don't want/need
'units': 'si'
}
r = requests.get(url, params=params)
try:
r = requests.get(url, params=params)
except:
raise Exception("An Error Occurred. Check Logs For More Information.")
data = r.json()
if r.status_code != 200:
raise Exception('Error: {}'.format(data['error']))
Expand Down
10 changes: 8 additions & 2 deletions sopel_modules/weather/providers/weather/openweathermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def openweathermap_forecast(bot, latitude, longitude, location):
'exclude': 'current,minutely,hourly',
'units': 'metric'
}
r = requests.get(url, params=params)
try:
r = requests.get(url, params=params)
except:
raise Exception("An Error Occurred. Check Logs For More Information.")
data = r.json()
if r.status_code != 200:
raise Exception('Error: {}'.format(data['message']))
Expand All @@ -42,7 +45,10 @@ def openweathermap_weather(bot, latitude, longitude, location):
'exclude': 'minutely,hourly,daily',
'units': 'metric'
}
r = requests.get(url, params=params)
try:
r = requests.get(url, params=params)
except:
raise Exception("An Error Occurred. Check Logs For More Information.")
data = r.json()
if r.status_code != 200:
raise Exception('Error: {}'.format(data['message']))
Expand Down

0 comments on commit d7474bd

Please sign in to comment.