correctly handle errors

This commit is contained in:
Romain Bignon 2010-11-11 00:17:40 +01:00
commit bf754b1859
2 changed files with 7 additions and 21 deletions

View file

@ -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

View file

@ -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