From 9114181bfeb6ea8c2f3af8db66428240dbc570d0 Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Wed, 3 Mar 2010 08:03:51 +1100 Subject: [PATCH] Handle Bit.ly exceptions Mainly for when there is no internet connection --- lib/articles.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/articles.rb b/lib/articles.rb index ecdd83f..eebacc3 100644 --- a/lib/articles.rb +++ b/lib/articles.rb @@ -24,16 +24,20 @@ module WezM end def short_url(url) - @bitly ||= Bitly.new('wezm', 'R_f2bfdace56c886671086eb0c8acb9ce7') - @cache ||= {} - unless u = @cache[url] - u = @bitly.shorten(url) - else - puts "Cache hit on #{url}" + begin + @bitly ||= Bitly.new('wezm', 'R_f2bfdace56c886671086eb0c8acb9ce7') + @cache ||= {} + unless u = @cache[url] + u = @bitly.shorten(url) + else + puts "Cache hit on #{url}" + end + u.short_url + rescue BitlyError + nil end - u.short_url end end end -end \ No newline at end of file +end