Errno::Econnreset: Connection Reset by Peer in Rails Using Rest-Client

How to catch error Connection reset by peer (Errno::ECONNRESET)

To catch it, do it just like any other exception:

begin
doc = Nokogiri::HTML(open(url))
rescue Errno::ECONNRESET => e
puts "we are handling it!"
end

A more useful pattern is to try a couple of times, then give up:

count = 0
begin
doc = Nokogiri::HTML(open(url))
rescue Errno::ECONNRESET => e
count += 1
retry unless count > 10
puts "tried 10 times and couldn't get #{url}: #{e}
end

How can I get a more information than `Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. - SSL_connect`

By setting RESTCLIENT_LOG=stdout environment variable you will see RestClient debug data in the terminal. Or you can replace stdout with a file path to write it out to a log file.

The reason may be an invalid SSL cert or just a flaky API endpoint that sometimes disconnects before returning a response.



Related Topics



Leave a reply



Submit