Permalink
Browse files

make sure we don't die if Twitter blows up

  • Loading branch information...
1 parent 80ed7ae commit ac6e7846ef6bb0026910256a88bc35ca47d51d52 @rsanheim rsanheim committed Nov 27, 2011
Showing with 14 additions and 1 deletion.
  1. +7 −1 app.rb
  2. +7 −0 spec/app_spec.rb
View
@@ -25,6 +25,12 @@ def last_shot
def last_tweet
settings.cache.fetch(:last_tweet) do
- Twitter.user_timeline("parenteau").first.text
+ begin
+ Twitter.user_timeline("parenteau").first.text
+ rescue => e
+ $stderr.puts "Could not retrieve latest tweet!"
+ $stderr.puts e
+ nil
+ end
end
end
View
@@ -36,6 +36,13 @@ def app
last_response.body.should include("Twitter requests are timing out")
end
+ it "shows friendly error message if twitter raises an exception" do
+ app.any_instance.stubs(:last_shot).returns(stub_everything("dribble shot"))
+ Twitter.expects(:user_timeline).raises(RuntimeError)
+ get "/"
+ last_response.body.should include("Twitter requests are timing out")
+ end
+
it "shows the latest tweet" do
app.any_instance.stubs(:last_shot).returns(stub_everything("dribble shot"))
app.any_instance.expects(:last_tweet).returns("this is a tweet!")

0 comments on commit ac6e784

Please sign in to comment.