Sha256: 687962ce7196efa9cee73730aa94b765357c8bc8c9a081f51773b591b5c8f472

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

module TrackerApi
  class Error < StandardError
    attr_reader :wrapped_exception, :response

    def initialize(wrapped_exception)
      @wrapped_exception = wrapped_exception
      @response          = wrapped_exception.response
      message            = if wrapped_exception.is_a?(Faraday::ParsingError)
                             wrapped_exception.message
                           elsif faraday_response_error?(wrapped_exception)
                             wrapped_exception.response.inspect
                           else
                             wrapped_exception.instance_variable_get(:@wrapped_exception).inspect
                           end
      super(message)
    end

    private

    # faraday 16.0 re-organized their errors. The errors we're interested in,
    # Faraday::ClientError before 16.0 and Faraday::ServerError introduced in
    # 16.0, are represented by this conditional.
    def faraday_response_error?(wrapped_exception)
      wrapped_exception.is_a?(Faraday::Error) &&
        wrapped_exception.respond_to?(:response)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tracker_api-1.16.0 lib/tracker_api/error.rb
tracker_api-1.15.0 lib/tracker_api/error.rb
tracker_api-1.14.0 lib/tracker_api/error.rb
tracker_api-1.13.0 lib/tracker_api/error.rb
tracker_api-1.12.0 lib/tracker_api/error.rb
tracker_api-1.11.0 lib/tracker_api/error.rb
tracker_api-1.10.0 lib/tracker_api/error.rb