diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-02-24 21:48:34 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-02-25 21:41:26 +0100 |
commit | b840a254c1ca755123d4b02907ee27c08a6a4ec9 (patch) | |
tree | bdf27a62f52f00c79a1e9fd6be86528afc55836a /data | |
parent | 4e4a5b8a91b3a5737773aab0ed7e67180f01a982 (diff) |
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.
Diffstat (limited to 'data')
-rw-r--r-- | data/rbot/plugins/lastfm.rb | 10 |
1 files changed, 6 insertions, 4 deletions
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 |