当たり前の事かも知れないのでコード読んでて、なんでってなったのでメモ書き
サンプル
require 'net/http'
begin
http = Net::HTTP.new('http://example.com', 80)
http.open_timeout = 5 # タイムアウト系のエラーが出るのを期待
http.read_timeout = 10
res = http.request(Net::HTTP::Get.new('/'))
# たぶんレスポンスで分岐して処理をする
rescue Timeout::Error
# timeout error
rescue => e
# other error
end
Net::HTTP のエラー
Net::HTTP を眺めていると、それぞれのタイムアウト設定の説明には以下のように記載されています。
open_timeout
If the HTTP object cannot open a connection in this many seconds, it raises a Net::OpenTimeout exception.
read_timeout
If the HTTP object cannot read data in this many seconds, it raises a Net::ReadTimeout exception. The default value is 60 seconds.
なので、例外としてはそれぞれを補足するのかなぁと思っていました。
Timeout::Error のサブクラスだった
ということでした。
Inherits:Timeout::Error
なるほどでした。なんか timeout
を使った時に出るものなのかと思ってました。