def rebuild_response_from_open_uri_exception(exception)
      code, message = exception.io.status

      response_class = Net::HTTPResponse::CODE_TO_OBJ.fetch(code)
      response       = response_class.new(nil, code, message)

      exception.io.metas.each do |name, values|
        values.each { |value| response.add_field(name, value) }
      end

      response
    end
def rebuild_response_from_open_uri_exception(exception)
      code, message = exception.io.status

      response_class = Net::HTTPResponse::CODE_TO_OBJ.fetch(code)
      response       = response_class.new(nil, code, message)

      exception.io.metas.each do |name, values|
        values.each { |value| response.add_field(name, value) }
      end

      response
    end
When open-uri raises an exception, it doesn't expose the response object.
 Fortunately, the exception object holds response data that can be used to
 rebuild the Net::HTTP response object.