Skip to content

Commit

Permalink
catch error on http request timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskite committed Feb 2, 2011
1 parent 2c974c2 commit bd5bf64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/anemone/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def fetch_pages(url, referer = nil, depth = nil)
end

return pages
rescue => e
rescue Exception => e
if verbose?
puts e.inspect
puts e.backtrace
Expand Down Expand Up @@ -116,7 +116,8 @@ def get_response(url, referer = nil)
response_time = ((finish - start) * 1000).round
@cookie_store.merge!(response['Set-Cookie']) if accept_cookies?
return response, response_time
rescue EOFError
rescue Timeout::Error, Net::HTTPBadResponse, EOFError => e
puts e.inspect if verbose?
refresh_connection(url)
retries += 1
retry unless retries > 3
Expand Down
10 changes: 8 additions & 2 deletions spec/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,11 @@ module Anemone
describe Storage::PStore do
it_should_behave_like "crawl"

before(:each) do
before(:all) do
@test_file = 'test.pstore'
end

before(:each) do
File.delete(@test_file) if File.exists?(@test_file)
@opts = {:storage => Storage.PStore(@test_file)}
end
Expand All @@ -247,8 +250,11 @@ module Anemone
describe Storage::TokyoCabinet do
it_should_behave_like "crawl"

before(:each) do
before(:all) do
@test_file = 'test.tch'
end

before(:each) do
File.delete(@test_file) if File.exists?(@test_file)
@opts = {:storage => @store = Storage.TokyoCabinet(@test_file)}
end
Expand Down

0 comments on commit bd5bf64

Please sign in to comment.