# File lib/rhc/rest.rb, line 165
    def request(request, &block)
      tried = 0
      begin
        debug "Request: #{request.inspect}" if debug?
        begin
          response = request.execute
        ensure
          debug "Response: #{response.inspect}" rescue nil if debug?
        end
        #set cookie
        rh_sso = response.cookies['rh_sso']
        if not rh_sso.nil?
          @@headers["cookie"] = "rh_sso=#{rh_sso}"
        end
        if block_given? 
          yield response
        else
          parse_response(response) unless response.nil? or response.code == 204
        end
      rescue RestClient::RequestTimeout => e
        raise TimeoutException.new(
          "Connection to server timed out. "\
          "It is possible the operation finished without being able "\
          "to report success. Use 'rhc domain show' or 'rhc app show' "\
          "to see the status of your applications.")
      rescue RestClient::ServerBrokeConnection => e
        raise ConnectionException.new(
          "Connection to server got interrupted: #{e.message}")
      rescue RestClient::BadGateway => e
        debug "ERROR: Received bad gateway from server, will retry once if this is a GET" if debug?
        retry if (tried += 1) < 2 && request.method.to_s.upcase == "GET"
        raise ConnectionException.new(
          "An error occurred while communicating with the server (#{e.message}). This problem may only be temporary."\
          "#{RestClient.proxy.present? ? " Check that you have correctly specified your proxy server '#{RestClient.proxy}' as well as your OpenShift server '#{request.url}'." : " Check that you have correctly specified your OpenShift server '#{request.url}'."}")
      rescue RestClient::ExceptionWithResponse => e
        process_error_response(e.response, request.url)
      rescue SocketError => e
        raise ConnectionException.new(
          "Unable to connect to the server (#{e.message})."\
          "#{RestClient.proxy.present? ? " Check that you have correctly specified your proxy server '#{RestClient.proxy}' as well as your OpenShift server '#{request.url}'." : " Check that you have correctly specified your OpenShift server '#{request.url}'."}")
      rescue => e
        logger.debug e.backtrace.join("\n  ") if debug?
        raise ResourceAccessException.new(
          "Failed to access resource: #{e.message}")
      ensure
        debug "Response: #{response}" if debug?
      end
    end