123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::Remote::Response Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: rb/lib/selenium/webdriver/remote/response.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(code, payload = nil) ⇒ Response

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/response.rb', line 30

def initialize(code, payload = nil)
  @code = code
  @payload = payload || {}

  assert_ok
end

Instance Attribute Details

#code (readonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/response.rb', line 28

attr_reader :code, :payload

#payload (readonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/response.rb', line 28

attr_reader :code, :payload

Instance Method Details

#[](key)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/response.rb', line 45

def [](key)
  @payload[key]
end

#add_cause(ex, error, backtrace) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/response.rb', line 59

def add_cause(ex, error, backtrace)
  cause = Error::WebDriverError.new
  backtrace = backtrace_from_remote(backtrace) if backtrace.is_a?(Array)
  cause.set_backtrace(backtrace)
  raise ex, cause: cause
rescue Error.for_error(error)
  ex
end

#assert_ok (private)

Raises:

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/response.rb', line 51

def assert_ok
  e = error
  raise e if e
  return unless @code.nil? || @code >= 400

  raise Error::ServerError, self
end

#backtrace_from_remote(server_trace) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/response.rb', line 68

def backtrace_from_remote(server_trace)
  server_trace.filter_map do |frame|
    next unless frame.is_a?(Hash)

    file = frame['fileName']
    line = frame['lineNumber']
    method = frame['methodName']

    class_name = frame['className']
    file = "#{class_name}(#{file})" if class_name

    method = 'unknown' if method.nil? || method.empty?

    "[remote server] #{file}:#{line}:in `#{method}'"
  end
end

#error

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/response.rb', line 37

def error
  error, message, backtrace = process_error
  klass = Error.for_error(error) || return
  ex = klass.new(message)
  add_cause(ex, error, backtrace)
  ex
end

#process_error (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/response.rb', line 85

def process_error
  return unless self['value'].is_a?(Hash)

  [
    self['value']['error'],
    self['value']['message'],
    self['value']['stacktrace']
  ]
end