instance method Net::HTTPExceptions#response

response -> Net::HTTPResponse[permalink][rdoc]

例外の原因となったレスポンスオブジェクトを返します。



require 'net/http'

uri = "http://www.example.com/invalid.html"
response = Net::HTTP.get_response(URI.parse(uri))
begin
  response.value
rescue => e
  e.response # => #<Net::HTTPNotFound 404 Not Found readbody=true>
end