Permalink
Browse files

Added catching of HTTP 403 errors thrown by Freebase

  • Loading branch information...
1 parent e7b0ad3 commit 3c945450d16b2dd5d2e61c84c5865bdf02f1d38a @njh committed Nov 19, 2013
Showing with 15 additions and 0 deletions.
  1. +2 −0 lib/thing.rb
  2. +13 −0 spec/thing_spec.rb
View
@@ -71,6 +71,8 @@ def fetch_freebase_uris
$stderr.puts "Timed out while reading from Freebase: #{e.message}"
rescue FreebaseApi::Exception => e
$stderr.puts "Error while reading from Freebase: #{e.message}"
+ rescue Net::HTTPServerException => e
+ $stderr.puts "Error while making HTTP request to Freebase: #{e.message}"
end
end
end
View
@@ -201,6 +201,19 @@
end
end
+ context "when FreebaseApi raises an a HTTPServerException exception" do
+ it "should send a message to stderr" do
+ response = Net::HTTPForbidden.new("1.1", "403", "Forbidden")
+ allow(FreebaseApi).to receive(:lookup_wikipedia_pageid).and_raise(Net::HTTPServerException.new('403 "Forbidden"', response))
+ previous_stderr, $stderr = $stderr, StringIO.new
+
+ @thing.freebase_mid_uri
+ $stderr.string.should == "Error while making HTTP request to Freebase: 403 \"Forbidden\"\n"
+
+ $stderr = previous_stderr
+ end
+ end
+
it "should have a single external like of type RDF::URI" do
@thing.externallinks.should == [RDF::URI('http://www.fife.50megs.com/ceres-history.htm')]
end

0 comments on commit 3c94545

Please sign in to comment.