Include raw_response in error message in weather segment

Closes #1112
Ref #1119
This commit is contained in:
ZyX 2014-10-18 20:28:18 +04:00
parent f5b9fc24e4
commit 1350fbe88e
1 changed files with 9 additions and 4 deletions

View File

@ -139,11 +139,16 @@ class WeatherSegment(KwThreadedSegment):
raw_response = urllib_read(url) raw_response = urllib_read(url)
if not raw_response: if not raw_response:
self.error('Failed to get response') self.error('Failed to get response')
return return None
response = json.loads(raw_response) response = json.loads(raw_response)
condition = response['query']['results']['weather']['rss']['channel']['item']['condition'] try:
condition_code = int(condition['code']) condition = response['query']['results']['weather']['rss']['channel']['item']['condition']
temp = float(condition['temp']) condition_code = int(condition['code'])
temp = float(condition['temp'])
except (KeyError, ValueError):
self.exception('Yahoo returned malformed or unexpected response: {0}', repr(raw_response))
return None
try: try:
icon_names = weather_conditions_codes[condition_code] icon_names = weather_conditions_codes[condition_code]