From b840a254c1ca755123d4b02907ee27c08a6a4ec9 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 24 Feb 2009 21:48:34 +0100 Subject: lastfm: catch all errors when connecting Since httputil.get_response() can raise exceptions, catch them into an appropriate block. Turn a missing response body into a runtime error to handle this error conditions consistently with other exceptions. --- data/rbot/plugins/lastfm.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'data/rbot/plugins') diff --git a/data/rbot/plugins/lastfm.rb b/data/rbot/plugins/lastfm.rb index 9be57d16..7438583d 100644 --- a/data/rbot/plugins/lastfm.rb +++ b/data/rbot/plugins/lastfm.rb @@ -469,10 +469,12 @@ class LastFmPlugin < Plugin uri << "&period=#{period_uri}" end - res = @bot.httputil.get_response(uri) - unless res.body - m.reply _("I had problems accessing last.fm") - return + begin + res = @bot.httputil.get_response(uri) + raise _("no response body") unless res.body + rescue Exception => e + m.reply _("I had problems accessing last.fm: %{e}") % {:e => e.message} + return end doc = Document.new(res.body) unless doc -- cgit v1.2.3