Sha256: 56dd8f21d9592f8036ad3b81cea9fbfcc2d732206919f5c5f8a67899376b9ee5

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

module Faraday
  class Error < StandardError; end
  class MissingDependency < Error; end

  class ClientError < Error
    attr_reader :response

    def initialize(ex, response = nil)
      @wrapped_exception = nil
      @response = response

      if ex.respond_to?(:backtrace)
        super(ex.message)
        @wrapped_exception = ex
      elsif ex.respond_to?(:each_key)
        super("the server responded with status #{ex[:status]}")
        @response = ex
      else
        super(ex.to_s)
      end
    end

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

    def inspect
      inner = ''
      if @wrapped_exception
        inner << " wrapped=#{@wrapped_exception.inspect}"
      end
      if @response
        inner << " response=#{@response.inspect}"
      end
      if inner.empty?
        inner << " #{super}"
      end
      %(#<#{self.class}#{inner}>)
    end
  end

  class ConnectionFailed < ClientError;   end
  class ResourceNotFound < ClientError;   end
  class ParsingError     < ClientError;   end

  class TimeoutError < ClientError
    def initialize(ex = nil)
      super(ex || "timeout")
    end
  end

  class SSLError < ClientError
  end

  [:MissingDependency, :ClientError, :ConnectionFailed, :ResourceNotFound,
   :ParsingError, :TimeoutError, :SSLError].each do |const|
    Error.const_set(const, Faraday.const_get(const))
  end
end

Version data entries

7 entries across 6 versions & 2 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/faraday-0.11.0/lib/faraday/error.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/faraday-0.11.0/lib/faraday/error.rb
faraday-0.12.0.1 lib/faraday/error.rb
tdiary-5.0.4 vendor/bundle/gems/faraday-0.11.0/lib/faraday/error.rb
faraday-0.11.0 lib/faraday/error.rb
faraday-0.10.1 lib/faraday/error.rb
faraday-0.10.0 lib/faraday/error.rb