correctly handle errors
This commit is contained in:
parent
6c22505f71
commit
bf754b1859
2 changed files with 7 additions and 21 deletions
|
|
@ -48,16 +48,9 @@ class WetBoobs(ReplApplication):
|
||||||
|
|
||||||
Get current weather.
|
Get current weather.
|
||||||
"""
|
"""
|
||||||
try:
|
for backend, current in self.do('get_current', city):
|
||||||
for backend, current in self.do('get_current', city):
|
self.format(current)
|
||||||
self.format(current)
|
self.flush()
|
||||||
self.flush()
|
|
||||||
except CallErrors, e:
|
|
||||||
for error in e:
|
|
||||||
if isinstance(error, CityNotFound):
|
|
||||||
print >>sys.stderr, 'City "%s" not found' % city
|
|
||||||
else:
|
|
||||||
raise error
|
|
||||||
|
|
||||||
def do_forecasts(self, city):
|
def do_forecasts(self, city):
|
||||||
"""
|
"""
|
||||||
|
|
@ -65,13 +58,6 @@ class WetBoobs(ReplApplication):
|
||||||
|
|
||||||
Get forecasts.
|
Get forecasts.
|
||||||
"""
|
"""
|
||||||
try:
|
for backend, forecast in self.do('iter_forecast', city):
|
||||||
for backend, forecast in self.do('iter_forecast', city):
|
self.format(forecast)
|
||||||
self.format(forecast)
|
self.flush()
|
||||||
self.flush()
|
|
||||||
except CallErrors, e:
|
|
||||||
for error in e:
|
|
||||||
if isinstance(error, CityNotFound):
|
|
||||||
print >>sys.stderr, 'City "%s" not found' % city
|
|
||||||
else:
|
|
||||||
raise error
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class YahooBackend(BaseBackend, ICapWeather):
|
||||||
dom = minidom.parse(handler)
|
dom = minidom.parse(handler)
|
||||||
handler.close()
|
handler.close()
|
||||||
if not dom.getElementsByTagName('yweather:condition'):
|
if not dom.getElementsByTagName('yweather:condition'):
|
||||||
raise CityNotFound()
|
raise CityNotFound('City not found: %s' % city_id)
|
||||||
|
|
||||||
return dom
|
return dom
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue