class Faraday::Error

Faraday error base class.

def backtrace

def backtrace
  if @wrapped_exception
    @wrapped_exception.backtrace
  else
    super
  end
end

def build_error_message_from_env(env)

def build_error_message_from_env(env)
  # Faraday::Env is internal - we can make reasonable assumptions about its structure
  build_status_error_message(env.status, env.method, env.url)
end

def build_error_message_from_hash(hash)

def build_error_message_from_hash(hash)
  # Be defensive with external Hash objects - they might be missing keys
  status = hash.fetch(:status, nil)
  request = hash.fetch(:request, nil)
  return fallback_error_message(status) if request.nil?
  method = request.fetch(:method, nil)
  url = request.fetch(:url, nil)
  build_status_error_message(status, method, url)
end

def build_status_error_message(status, method, url)

def build_status_error_message(status, method, url)
  method_str = method ? method.to_s.upcase : ''
  url_str = url ? url.to_s : ''
  "the server responded with status #{status} for #{method_str} #{url_str}"
end

def exc_msg_and_response(exc, response = nil)

Pulls out potential parent exception and response hash.
def exc_msg_and_response(exc, response = nil)
  case exc
  when Exception
    [exc, exc.message, response]
  when Hash
    [nil, build_error_message_from_hash(exc), exc]
  when Faraday::Env
    [nil, build_error_message_from_env(exc), exc]
  else
    [nil, exc.to_s, response]
  end
end

def exc_msg_and_response!(exc, response = nil)

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

:body - String HTTP request body.
header values.
:headers - String key/value hash of HTTP request
present in the request.
:params - String key/value hash of query params
:url_path - String with the url path requested.
:url - URI object with the url requested.
:method - Symbol with the request HTTP method.
:request - Hash
:body - Optional string HTTP response body.
values.
:headers - String key/value hash of HTTP response header
:status - Optional integer HTTP response status
response - Hash
exc - Either an Exception, a string message, or a response hash.
instance variables.
Pulls out potential parent exception and response hash, storing them in
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

def fallback_error_message(status)

def fallback_error_message(status)
  "the server responded with status #{status} - method and url are not available " \
    'due to include_request: false on Faraday::Response::RaiseError middleware'
end

def initialize(exc = nil, response = nil)

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

def inspect

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

def response_body

def response_body
  return unless @response
  @response.is_a?(Faraday::Response) ? @response.body : @response[:body]
end

def response_headers

def response_headers
  return unless @response
  @response.is_a?(Faraday::Response) ? @response.headers : @response[:headers]
end

def response_status

def response_status
  return unless @response
  @response.is_a?(Faraday::Response) ? @response.status : @response[:status]
end