class Faraday::Error

Faraday error base class.

Attributes

Public Class Methods

Calls superclass method
# File lib/faraday/error.rb, line 9
def initialize(exc = nil, response = nil)
  @wrapped_exception = nil unless defined?(@wrapped_exception)
  @response = nil unless defined?(@response)
  super(exc_msg_and_response!(exc, response))
end

Public Instance Methods

Calls superclass method
# File lib/faraday/error.rb, line 15
def backtrace
  if @wrapped_exception
    @wrapped_exception.backtrace
  else
    super
  end
end
# File lib/faraday/error.rb, line 23
def inspect
  inner = +''
  inner << " wrapped=#{@wrapped_exception.inspect}" if @wrapped_exception
  inner << " response=#{@response.inspect}" if @response
  inner << " #{super}" if inner.empty?
  %(#<#{self.class}#{inner}>)
end
# File lib/faraday/error.rb, line 43
def response_body
  return unless @response

  @response.is_a?(Faraday::Response) ? @response.body : @response[:body]
end
# File lib/faraday/error.rb, line 37
def response_headers
  return unless @response

  @response.is_a?(Faraday::Response) ? @response.headers : @response[:headers]
end
# File lib/faraday/error.rb, line 31
def response_status
  return unless @response

  @response.is_a?(Faraday::Response) ? @response.status : @response[:status]
end

Protected Instance Methods

Pulls out potential parent exception and response hash.

# File lib/faraday/error.rb, line 81
def exc_msg_and_response(exc, response = nil)
  return [exc, exc.message, response] if exc.respond_to?(:backtrace)

  return [nil, "the server responded with status #{exc[:status]}", exc] \
    if exc.respond_to?(:each_key)

  [nil, exc.to_s, response]
end

Pulls out potential parent exception and response hash, storing them in instance variables. exc - Either an Exception, a string message, or a response hash. response - Hash

:status  - Optional integer HTTP response status
:headers - String key/value hash of HTTP response header
           values.
:body    - Optional string HTTP response body.
:request - Hash
             :method   - Symbol with the request HTTP method.
             :url      - URI object with the url requested.
             :url_path - String with the url path requested.
             :params   - String key/value hash of query params
                       present in the request.
             :headers  - String key/value hash of HTTP request
                       header values.
             :body     - String HTTP request body.

If a subclass has to call this, then it should pass a string message to ‘super`. See NilStatusError.

# File lib/faraday/error.rb, line 71
def exc_msg_and_response!(exc, response = nil)
  if @response.nil? && @wrapped_exception.nil?
    @wrapped_exception, msg, @response = exc_msg_and_response(exc, response)
    return msg
  end

  exc.to_s
end