class Faraday::Error
Faraday
error base class.
Attributes
Public Class Methods
Source
# 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
Calls superclass method
Public Instance Methods
Source
# File lib/faraday/error.rb, line 15 def backtrace if @wrapped_exception @wrapped_exception.backtrace else super end end
Calls superclass method
Source
# 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
Source
# File lib/faraday/error.rb, line 43 def response_body return unless @response @response.is_a?(Faraday::Response) ? @response.body : @response[:body] end
Source
# File lib/faraday/error.rb, line 37 def response_headers return unless @response @response.is_a?(Faraday::Response) ? @response.headers : @response[:headers] end
Source
# 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
Source
# File lib/faraday/error.rb, line 81 def exc_msg_and_response(exc, response = nil) if exc.is_a?(Exception) [exc, exc.message, response] elsif exc.is_a?(Hash) http_status = exc.fetch(:status) request = exc.fetch(:request, nil) if request.nil? exception_message = "the server responded with status #{http_status} - method and url are not available " \ 'due to include_request: false on Faraday::Response::RaiseError middleware' else exception_message = "the server responded with status #{http_status} for #{request.fetch(:method).upcase} " \ "#{request.fetch(:url)}" end [nil, exception_message, exc] else [nil, exc.to_s, response] end end
Pulls out potential parent exception and response hash.
Source
# 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
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
.