user2611714 user2611714 - 11 months ago 89
Ruby Question

Rails 3.2.12: Uninitialized constant Net::ReadTimeout

So, I have the following code (connection.rb):

require 'net/http'
require 'net/https'
require 'openssl'

class Connection
def request
body = '<?xml version="1.0" encoding="UTF-8"?>...'
path = '/path'
http ='', '1234')
http.read_timeout = 60
p "=1"
http.request_post(path, body, {'Content-Type' => 'application/xml'})
p "=2"
rescue Net::ReadTimeout => ex

In the string http.request_post(...) I get the output:

NameError: uninitialized constant Net::ReadTimeout
/home/user/invp/lib/connection.rb:76:in `rescue in request'
/home/user/invp/lib/connection.rb:26:in `request'
/home/user/invp/lib/tasks/task.rake:225:in `block (2 levels) in <top (required)>'

My environment:

user@vm-dev:~/invp$ ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
user@vm-dev:~/invp$ rails --version
Rails 3.2.12

What's wrong?


For ruby 1.9.3 it raises TimeoutError Exception.
For ruby 2.3.1 it raises Net::ReadTimeout Exception.

So you should use rescue TimeoutError or update your ruby version.

refs (search for read_timeout at the end of the page):

One more information: Net::ReadTimeout is a subclass of TimeoutError and it seems to be added on ruby-2.0.0: