P
P
Pavel2018-01-28 17:38:04
ruby
Pavel, 2018-01-28 17:38:04

How to get around this Faraday::ConnectionFailed error?

There is a simple code. Every 10 seconds it sends an http request and receives a response.

require 'vk-ruby'

app = VK::Application.new(app_id: ------, version: '5.71', access_token: '--------------------')

check = 0
while true
    get = app.vk_call 'messages.getDialogs?count=2'
    body = get['items'][0]['message']['body']
    
    if body != check
        p body
        check = body
    end
    
    sleep 10
end

But occasionally an error occurs and the program closes.
spoiler
/usr/lib/ruby/2.3.0/net/http.rb:880:in `initialize': execution expired (Faraday::ConnectionFailed)
from /usr/lib/ruby/2.3.0/net/http.rb:880:in `open'
from /usr/lib/ruby/2.3.0/net/http.rb:880:in `block in connect'
from /usr/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
from /usr/lib/ruby/2.3.0/net/http.rb:878:in `connect'
from /usr/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
from /usr/lib/ruby/2.3.0/net/http.rb:852:in `start'
from /usr/lib/ruby/2.3.0/net/http.rb:1398:in `request'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/adapter/net_http.rb:38:in `block in call'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/adapter/net_http.rb:85:in `with_net_http_connection'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/adapter/net_http.rb:33:in `call'
from /var/lib/gems/2.3.0/gems/vk-ruby-1.0.2/lib/vk-ruby/middlewares/http_errors.rb:8:in `call'
from /var/lib/gems/2.3.0/gems/faraday_middleware-0.12.2/lib/faraday_middleware/response_middleware.rb:31:in `call'
from /var/lib/gems/2.3.0/gems/vk-ruby-1.0.2/lib/vk-ruby/middlewares/api_errors.rb:8:in `call'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/request/url_encoded.rb:15:in `call'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/request/multipart.rb:15:in `call'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/rack_builder.rb:143:in `build_response'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/connection.rb:387:in `run_request'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/connection.rb:175:in `post'
from /var/lib/gems/2.3.0/gems/vk-ruby-1.0.2/lib/vk-ruby/core.rb:66:in `request'
from /var/lib/gems/2.3.0/gems/vk-ruby-1.0.2/lib/vk-ruby/core.rb:26:in `vk_call'
from redis.rb:17:in `'

How can this situation be resolved? Or is it possible to set a condition, if this error occurs with the connection, then wait another 10 seconds and repeat the request. How to implement?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kozlov, 2018-01-29
@Vidgar

How to "try again" when exceptions happen in Ruby

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question