1

I have a ruby on rails application which hit salesforce api and log the error. There are some scenarios where system is generate ReadNet Timeout error. I just wanted to generate the error manually so I can handle different logics in my code

Ayaz Ahmad Tarar
  • 534
  • 8
  • 24

1 Answers1

2

From the Ref I have found the solution that was exact thing I was looking for.

begin
  conn = Faraday::Connection.new('https://httpstat.us')
  conn.options.timeout = 1
  conn.options.open_timeout = 1
  conn.options
  # => #<Faraday::RequestOptions timeout=1, open_timeout=1>
  conn.get('/200?sleep=2000')
  # => Faraday::TimeoutError (Net::ReadTimeout)

rescue Exception => e
  #you can catch exception here
  debugger
end 
Ayaz Ahmad Tarar
  • 534
  • 8
  • 24
  • It's allso possible to set timeout through initialize options: `Faraday::Connection.new('https://httpstat.us', request: { timeout: 1.second }).get('/200?sleep=2000')` – Lev Lukomsky Mar 23 '21 at 15:17