How can I handle Connection timed out error in ruby Net/HTTP?

turbod

I try this code, but when the proxy is too slow I get connection timed out error. How can I solve this? I tried Exception handling but doesn't work. Can anybody help?

 Net::HTTP.new('example.com', nil, '140.113.182.81', '808').start { |http|  

      begin   
        response = http.request  
        p response  
      rescue Timeout::Error  
        p 'timed out'   
      end  
    }  
Simone Carletti

The Timeout::Error is raised by the Net::HTTP.connect method that is executed by start, not by request.

It means that in order to rescue the timeout, the whole Net::HTTP call should be inside the begin block.

  begin   
    Net::HTTP.new('example.com', nil, '140.113.182.81', '808').start do |http|  
      response = http.request  
      p response  
    end
  rescue Timeout::Error  
    p 'timed out'   
  end  

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

pooled connection timed out

From Dev

Why do I get 'Handshake timed out'? How can I configure timeout period?

From Dev

PHPMailer connection timed out

From Dev

TinyTds Error: Adaptive Server connection timed out

From Dev

Gradle ant ftp error: "425 Connection timed out"

From Dev

unix sockets - can't connect to server (connection timed out)

From Dev

Connection timed out error in intellij Idea

From Dev

android studio error Error:Connection timed out

From Dev

rabbitMQ Connection timed out

From Dev

golang :how do I handle index out of range error?

From Dev

Socket Error 110: Connection Timed Out - Android Delphi SMTP Gmail

From Dev

Error with timed out bluetooth connection

From Dev

How to handle a redirect in AJAX after session timed out?

From Dev

Why do I get 'Handshake timed out'? How can I configure timeout period?

From Dev

Error transferring file: Connection timed out: connect in maven.

From Dev

The connection has timed out

From Dev

PuTTY returns Network error: Connection timed out

From Dev

SSH Connection Timed Out

From Dev

Connection timed out error

From Dev

Error 522: Connection timed out

From Dev

How can I catch this PHP connection error?

From Dev

How can I handle the error "IndexError: string index out of range"

From Dev

rabbitMQ Connection timed out

From Dev

How do I fix the "we can't reach this page" error or "err_connection_timed_out" on my browsers?

From Dev

Connection to MSSQL timed out

From Dev

ssh error: connection timed out

From Dev

MailEnable error connection timed out

From Dev

SMTP -> ERROR: Failed to connect to server: Connection timed out (110)

From Dev

Mongodb is throwing "connection timed out" error

Related Related

HotTag

Archive